diff --git a/lib/synth-audio.js b/lib/synth-audio.js index dbf5740..243d10d 100644 --- a/lib/synth-audio.js +++ b/lib/synth-audio.js @@ -1329,7 +1329,7 @@ const synthCartesia = async(logger, { try { const client = new CartesiaClient({ apiKey: api_key }); const sampleRate = 48000; - const mp3 = await client.tts.bytes({ + const mp3Stream = await client.tts.bytes({ modelId: model_id, transcript: text, voice: { @@ -1363,8 +1363,16 @@ const synthCartesia = async(logger, { sampleRate }, }); + + // bytes() returns a ReadableStream - collect all chunks + const chunks = []; + for await (const chunk of mp3Stream) { + chunks.push(chunk); + } + const audioBuffer = Buffer.concat(chunks); + return { - audioContent: Buffer.from(mp3), + audioContent: audioBuffer, extension: 'mp3', sampleRate }; diff --git a/test/synth.js b/test/synth.js index 8f088e4..cf09b48 100644 --- a/test/synth.js +++ b/test/synth.js @@ -716,7 +716,7 @@ test('Cartesia speech synth tests', async(t) => { text, renderForCaching: true }); - t.ok(!opts.servedFromCache, `successfully playht eleven audio to ${opts.filePath}`); + t.ok(!opts.servedFromCache, `successfully cartesia eleven audio to ${opts.filePath}`); } catch (err) { console.error(JSON.stringify(err));