@speechly/browser-client
Version:
JavaScript client for Speechly Streaming API
38 lines (37 loc) • 1.36 kB
TypeScript
import { AudioSourceState } from './types';
/**
* Gets browser based microphone using the window.navigator.mediaDevices interface.
* The exposed `mediaStream` can be attached to a `BrowserClient` instance.
* @public
*/
export declare class BrowserMicrophone {
private muted;
private initialized;
private state;
private readonly nativeResamplingSupported;
private readonly autoGainControlSupported;
private readonly debug;
mediaStream?: MediaStream;
stateChangeCbs: Array<(state: AudioSourceState) => void>;
constructor();
/**
* Adds a listener for the state changes of the client.
* @param cb - the callback to invoke on a client state change.
*/
onStateChange(cb: (state: AudioSourceState) => void): void;
/**
* Initializes the microphone. Needs to happen after a user interaction in the view.
* The reason for that is that it's required for user to first interact with the page,
* before it can capture or play audio and video, for privacy and user experience reasons.
*/
initialize(): Promise<void>;
setState(newState: AudioSourceState): void;
/**
* Closes the microphone, releases all resources and stops the Speechly client.
*/
close(): Promise<void>;
/**
* @returns true if microphone is open
*/
isRecording(): boolean;
}