Generate audio and trigger a file download in the browser.
async function ttsDownloadFile(client: Cartesia): Promise<void> { /** Generate audio and trigger a file download in the browser. */ const response = await client.tts.generate({ model_id: 'sonic-3', transcript: 'This audio will be downloaded as a file.', voice: { mode: 'id', id: '6ccbfb76-1fc6-48f7-b71d-91ac6298247b' }, output_format: { container: 'wav', encoding: 'pcm_s16le', sample_rate: 44100 }, }); const blob = await response.blob(); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'speech.wav'; a.click(); URL.revokeObjectURL(url); }
Was this page helpful?