UNPKG

@nafr/echo-ui

Version:

A UI library born for WAA

37 lines (36 loc) 1.73 kB
/// <reference types="react" /> import * as Tone from 'tone'; import type { SpectrogramDataPoint } from '../main'; export interface UseSpectrogramProps { fftSize?: number; onReady?: () => void; onError?: () => void; } /** * useSpectrogram is a custom React hook for analyzing and visualizing audio frequencies using Tone.js. * It creates an FFT (Fast Fourier Transform) based analyzer to process audio data and provide spectrogram data points. * * @param {UseSpectrogramProps} props - The configuration properties for the hook. * @param {number} props.fftSize - The size of the FFT. Represents the window size in samples that is used when performing a FFT. * - Default value is 1024. * * @returns {object} An object containing various properties and methods to interact with the spectrogram: * - init: A method to initialize the analyser. * - analyser: An instance of Tone.Analyser used for analyzing audio frequencies. * - data: An array of spectrogram data points. * - getData: A method to fetch the latest spectrogram data from the analyser. * - observe: A method to start observing and updating the spectrogram data. * - cancelObserve: A method to stop observing the spectrogram data. * - error: A boolean indicating whether an error has occurred. * - errorMessage: A string containing the error message if an error has occurred. */ export declare const useSpectrogram: (props?: UseSpectrogramProps) => { analyser: import("react").MutableRefObject<Tone.Analyser | null>; data: SpectrogramDataPoint[]; init: () => void; getData: () => void; observe: () => void; cancelObserve: () => void; error: boolean; errorMessage: string; };