speech-provider
Version:
A unified interface for browser speech synthesis and Eleven Labs voices
124 lines • 5.12 kB
TypeScript
import { ElevenLabsVoiceData } from "./ElevenLabsTypes";
import { Utterance, Voice, VoiceProvider } from "./VoiceProvider";
/** The base URL for the Eleven Labs API */
export declare const ELEVEN_LABS_BASE_URL = "https://api.elevenlabs.io/v1";
/**
* A voice provider that uses the ElevenLabs API for high-quality text-to-speech.
* This provider requires an API key from ElevenLabs.
*
* @example
* ```typescript
* const provider = createElevenLabsVoiceProvider("your-api-key");
* const voices = await provider.getVoices({ lang: "en-US", minVoices: 1 });
* const voice = voices[0];
* const utterance = voice.createUtterance("Hello, world!");
* utterance.start();
* ```
*/
export declare class ElevenLabsVoiceProvider implements VoiceProvider {
name: string;
private apiKey;
private baseUrl;
private validateResponses;
private printVoiceProperties;
private cacheMaxAge;
/**
* Create a new ElevenLabs voice provider.
* @param apiKey - Your ElevenLabs API key
* @param baseUrl - The base URL for the ElevenLabs API (defaults to the official API)
* @param options - Additional options for the provider
* @param options.validateResponses - Whether to validate API responses against the schema
* @param options.printVoiceProperties - Whether to print voice properties for debugging
* @param options.cacheMaxAge - Maximum age of cached responses in seconds (default: 1 hour). Set to null to disable caching.
*/
constructor(apiKey: string, baseUrl?: string, options?: {
validateResponses?: boolean;
printVoiceProperties?: boolean;
cacheMaxAge?: number | null;
});
/**
* 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 ElevenLabs voices
*/
getVoices({ lang, minVoices, }: {
lang: string;
minVoices: number;
}): Promise<Voice[]>;
/**
* 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 first available voice or null if none is available
*/
getDefaultVoice({ lang }: {
lang: string;
}): Promise<Voice | null>;
}
/**
* A voice implementation that wraps an ElevenLabs voice.
*/
export declare class ElevenLabsVoice implements Voice {
private apiKey;
private voiceData;
provider: VoiceProvider;
private cacheMaxAge;
constructor(apiKey: string, voiceData: ElevenLabsVoiceData, provider: VoiceProvider, cacheMaxAge?: number | null);
/** The language code for the voice */
get lang(): string;
/** The display name of the voice */
get name(): string;
/** The unique identifier for the voice */
get id(): string;
/** A short description of the voice */
get description(): string | null;
/** The full description of the voice */
get longDescription(): string | undefined;
/**
* 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;
}
/**
* An utterance implementation that uses the ElevenLabs API to synthesize speech.
*/
export declare class ElevenLabsUtterance implements Utterance {
private apiKey;
private voiceId;
private languageCode;
private text;
private audio;
private onStartCallback;
private onEndCallback;
private cacheMaxAge;
constructor(apiKey: string, voiceId: string, languageCode: string, text: string, cacheMaxAge?: number | null);
/**
* Start speaking the utterance by fetching audio from ElevenLabs and playing it.
*/
start(): Promise<void>;
/** Stop speaking the utterance */
stop(): void;
/** Set the callback for when the utterance starts speaking */
set onstart(callback: () => void);
/** Set the callback for when the utterance finishes speaking */
set onend(callback: () => void);
}
/**
* Create a new Eleven Labs voice provider.
* @param apiKey - Your Eleven Labs API key
* @param baseUrl - The base URL for the Eleven Labs API (defaults to the official API)
* @param options - Additional options for the provider
* @param options.validateResponses - Whether to validate API responses against the schema
* @param options.printVoiceProperties - Whether to print voice properties for debugging
* @param options.cacheMaxAge - Maximum age of cached responses in seconds (default: 1 hour). Set to null to disable caching.
*/
export declare function createElevenLabsVoiceProvider(apiKey: string, baseUrl?: string, options?: {
validateResponses?: boolean;
printVoiceProperties?: boolean;
cacheMaxAge?: number | null;
}): VoiceProvider;
//# sourceMappingURL=ElevenLabsVoiceProvider.d.ts.map