export type SarvamModelAPITextToSpeechLanguage = 'bn-IN' | 'en-IN' | 'gu-IN' | 'hi-IN' | 'kn-IN' | 'ml-IN' | 'mr-IN' | 'od-IN' | 'pa-IN' | 'ta-IN' | 'te-IN'; export type SarvamModelAPITextToSpeechSpeaker = 'anushka' | 'abhilash' | 'manisha' | 'vidya' | 'arya' | 'karun' | 'hitesh' | 'aditya' | 'ritu' | 'priya' | 'neha' | 'rahul' | 'pooja' | 'rohan' | 'simran' | 'kavya' | 'amit' | 'dev' | 'ishita' | 'shreya' | 'ratan' | 'varun' | 'manan' | 'sumit' | 'roopa' | 'kabir' | 'aayan' | 'shubh' | 'ashutosh' | 'advait' | 'anand' | 'tanya' | 'tarun' | 'sunny' | 'mani' | 'gokul' | 'vijay' | 'shruti' | 'suhani' | 'mohit' | 'kavitha' | 'rehan' | 'soham' | 'rupali'; export type SarvamModelAPISpeechSampleRate = '8000' | '16000' | '22050' | '24000' | '32000' | '44100' | '48000'; export type SarvamModelAPITextToSpeechModel = 'bulbul:v2' | 'bulbul:v3'; export type SarvamModelAPISpeechStreamCodec = 'mp3' | 'linear16' | 'mulaw' | 'alaw' | 'opus' | 'flac' | 'aac' | 'wav'; export type SarvamModelAPISpeechStreamBitrate = '32k' | '64k' | '96k' | '128k' | '192k'; export type SarvamModelAPITextToSpeechStreamRequest = {text: string, target_language_code?: SarvamModelAPITextToSpeechLanguage | undefined, speaker?: (SarvamModelAPITextToSpeechSpeaker | null) | undefined, pitch?: (number | null) | undefined, pace?: (number | null) | undefined, loudness?: (number | null) | undefined, speech_sample_rate?: (SarvamModelAPISpeechSampleRate | null) | undefined, enable_preprocessing?: boolean | undefined, model?: SarvamModelAPITextToSpeechModel | undefined, temperature?: (number | null) | undefined, enable_cached_responses?: boolean | undefined, dict_id?: (string | null) | undefined, output_audio_codec?: SarvamModelAPISpeechStreamCodec | undefined, output_audio_bitrate?: SarvamModelAPISpeechStreamBitrate | undefined}; export type CreateApiTextToSpeechStreamArgs = {'api-subscription-key': string, body: SarvamModelAPITextToSpeechStreamRequest}; export type CreateApiTextToSpeechStreamOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Text-to-Speech Stream Audio * * POST /text-to-speech/stream */ export const createApiTextToSpeechStream = async (args: CreateApiTextToSpeechStreamArgs, options?: CreateApiTextToSpeechStreamOptions) => { const {baseUrl = "https://api.sarvam.ai", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/octet-stream") if (args['api-subscription-key'] != null) headers.set("api-subscription-key", String(args['api-subscription-key'])) const url = `${baseUrl.replace(/\/+$/, '')}/text-to-speech/stream${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };