@speechmatics/browser-audio-input-react
Version:
React hooks for managing audio inputs and permissions across browsers
60 lines (53 loc) • 2.31 kB
TypeScript
import { StartRecordingOptions, PCMRecorder } from '@speechmatics/browser-audio-input';
export * from '@speechmatics/browser-audio-input';
import * as react_jsx_runtime from 'react/jsx-runtime';
type AudioDevices = {
permissionState: 'prompt';
promptPermissions: () => void;
deviceList?: undefined;
} | {
permissionState: 'prompting';
promptPermissions?: undefined;
deviceList?: undefined;
} | {
permissionState: 'granted';
deviceList: ReadonlyArray<MediaDeviceInfo>;
promptPermissions?: undefined;
} | {
permissionState: 'denied';
promptPermissions?: undefined;
deviceList?: undefined;
};
declare function useAudioDevices(): AudioDevices;
type UsePCMAudioRecorderReturn = {
startRecording: (options: Omit<StartRecordingOptions, 'audioContext'>) => Promise<void>;
stopRecording: PCMRecorder['stopRecording'];
mute: PCMRecorder['mute'];
unmute: PCMRecorder['unmute'];
isMuted: boolean;
addEventListener: PCMRecorder['addEventListener'];
removeEventListener: PCMRecorder['removeEventListener'];
analyser: PCMRecorder['analyser'];
isRecording: boolean;
};
declare function usePCMAudioRecorder(workletScriptURL: string, audioContext: AudioContext | undefined): UsePCMAudioRecorderReturn;
interface IPCMAudioRecorderContext {
startRecording: (opts: Omit<StartRecordingOptions, 'audioContext'>) => Promise<void>;
stopRecording: PCMRecorder['stopRecording'];
mute: PCMRecorder['mute'];
unmute: PCMRecorder['unmute'];
addEventListener: PCMRecorder['addEventListener'];
removeEventListener: PCMRecorder['removeEventListener'];
analyser: PCMRecorder['analyser'];
isRecording: PCMRecorder['isRecording'];
isMuted: PCMRecorder['isMuted'];
audioContext?: AudioContext;
}
declare function usePCMAudioRecorderContext(): IPCMAudioRecorderContext;
declare function usePCMAudioListener(cb: (audio: Float32Array) => void): void;
declare function PCMAudioRecorderProvider({ workletScriptURL, children, audioContext, }: {
workletScriptURL: string;
children: React.ReactNode;
audioContext: AudioContext | undefined;
}): react_jsx_runtime.JSX.Element;
export { type AudioDevices, PCMAudioRecorderProvider, useAudioDevices, usePCMAudioListener, usePCMAudioRecorder, usePCMAudioRecorderContext };