speechly
Version:
A React component for text-to-speech functionality using the Speechify API
109 lines (108 loc) • 3.75 kB
TypeScript
interface VoiceCloneResponse {
display_name: string;
gender: 'male' | 'female';
locale: string;
id: string;
models: {
languages: Record<string, unknown>[];
name: string;
}[];
type: string;
avatar_image: string;
}
export interface TextToSpeechOptions {
audio_format?: 'wav' | 'mp3' | 'ogg' | 'aac';
language?: string;
model?: 'simba-base' | 'simba-english' | 'simba-multilingual' | 'simba-turbo';
options?: {
loudness_normalization?: boolean;
text_normalization?: boolean;
};
}
export interface TextToSpeechResponse {
audio_data: string;
audio_format: 'wav' | 'mp3' | 'ogg' | 'aac';
billable_characters_count: number;
speech_marks?: {
chunks?: Array<{
end?: number;
end_time?: number;
start?: number;
start_time?: number;
type?: string;
value?: string;
}>;
end?: number;
end_time?: number;
start?: number;
start_time?: number;
type?: string;
value?: string;
};
}
export interface Voice {
display_name: string;
gender: 'male' | 'female';
locale: string;
id: string;
models: {
languages: {
locale: string;
}[];
name: string;
}[];
type: string;
avatar_image: string;
preview_audio?: string;
tags?: string[];
}
/**
* Clones a voice using the Speechify API
* @param audioFile - The audio file containing the voice sample
* @param name - The name for the cloned voice
* @param gender - The gender of the voice ('male' or 'female')
* @param avatarFile - Optional avatar image file
* @returns Promise with the voice cloning response
*/
export declare const cloneVoice: (audioFile: File, name: string, gender: "male" | "female", avatarFile?: File, fullName?: string, email?: string) => Promise<VoiceCloneResponse>;
/**
* Converts a blob URL to a File object
* @param blobUrl - The blob URL to convert
* @param filename - The filename to use for the File
* @returns Promise with the File object
*/
export declare const blobUrlToFile: (blobUrl: string, filename: string) => Promise<File>;
/**
* Fetches the list of voices from the Speechify API
* @returns Promise with the list of voices
*/
export declare const voicesRefetchEvent: EventTarget;
export declare const getVoices: () => Promise<Voice[]>;
export declare const triggerVoicesRefetch: () => void;
/**
* Converts text to speech using the Speechify API
* @param input - The text to convert to speech
* @param voice_id - The ID of the voice to use
* @param options - Optional parameters for the text-to-speech conversion
* @returns Promise with the text-to-speech response
*/
export declare const textToSpeech: (input: string, voice_id: string, options?: TextToSpeechOptions) => Promise<TextToSpeechResponse>;
/**
* Plays audio data from a text-to-speech response
* @param audioData - Base64-encoded audio data
* @param audioFormat - Format of the audio data (wav, mp3, ogg, aac)
* @returns Promise that resolves when audio playback starts
*/
export declare const playTextToSpeechAudio: (audioData: string, audioFormat?: "wav" | "mp3" | "ogg" | "aac") => Promise<HTMLAudioElement>;
/**
* Converts text to speech and plays the audio
* @param input - The text to convert to speech
* @param voice_id - The ID of the voice to use
* @param options - Optional parameters for the text-to-speech conversion
* @returns Promise with the audio element and the full TTS response
*/
export declare const speakText: (input: string, voice_id: string, options?: TextToSpeechOptions) => Promise<{
audio: HTMLAudioElement;
response: TextToSpeechResponse;
}>;
export {};