speech-provider
Version:
A unified interface for browser speech synthesis and Eleven Labs voices
69 lines • 2.75 kB
TypeScript
import { Utterance, Voice, VoiceProvider } from "./VoiceProvider";
/**
* A voice provider that uses the browser's built-in speech synthesis.
* This provider is available in all modern browsers and doesn't require any API keys.
*/
export declare class BrowserVoiceProvider implements VoiceProvider {
name: string;
private voicesInitialized;
private voicesReadyPromise;
/**
* Get available voices for a given language code.
* @param options - The options for getting voices
* @param options.lang - The language code to match (e.g., "en-US")
* @param options.minVoices - The minimum number of voices to return
* @returns A promise that resolves to an array of browser voices
*/
getVoices({ lang, minVoices, }: {
lang: string;
minVoices: number;
}): Promise<BrowserSpeechSynthesisVoice[]>;
/**
* Ensures that the browser's speech synthesis voices are loaded.
* In some browsers, especially Chrome, voices are loaded asynchronously.
*/
private ensureVoicesLoaded;
/**
* Get the default voice for a given language code.
* @param options - The options for getting the default voice
* @param options.lang - The language code to match (e.g., "en-US")
* @returns A promise that resolves to the default voice or null if none is available
*/
getDefaultVoice({ lang, }: {
lang: string;
}): Promise<BrowserSpeechSynthesisVoice | null>;
/**
* Get browser voices for a given language code.
* @param lang - The language code to match
* @param minVoices - The minimum number of voices to return
* @returns An array of browser voices
* @private
*/
private getBrowserVoicesForLanguage;
}
/**
* A voice implementation that wraps the browser's SpeechSynthesisVoice.
*/
export declare class BrowserSpeechSynthesisVoice implements Voice {
lang: string;
provider: VoiceProvider;
private voice;
constructor(voice: SpeechSynthesisVoice, lang: string, provider: VoiceProvider);
/** Whether this is the default voice for its language */
get isDefault(): boolean;
/** The display name of the voice */
get name(): string;
/** The unique identifier for the voice */
get id(): string;
/** The description of the voice (e.g., "English (US)") */
get description(): string | null;
/**
* Create a new utterance with this voice.
* @param text - The text to speak
* @returns A new utterance that can be started and stopped
*/
createUtterance(text: string): Utterance;
}
/** The default browser voice provider instance */
export declare const browserVoiceProvider: BrowserVoiceProvider;
//# sourceMappingURL=BrowserVoiceProvider.d.ts.map