mirror of
https://github.com/jambonz/speech-utils.git
synced 2025-12-19 03:37:49 +00:00
fixed cartesia collect audio from stream
This commit is contained in:
@@ -1329,7 +1329,7 @@ const synthCartesia = async(logger, {
|
|||||||
try {
|
try {
|
||||||
const client = new CartesiaClient({ apiKey: api_key });
|
const client = new CartesiaClient({ apiKey: api_key });
|
||||||
const sampleRate = 48000;
|
const sampleRate = 48000;
|
||||||
const mp3 = await client.tts.bytes({
|
const mp3Stream = await client.tts.bytes({
|
||||||
modelId: model_id,
|
modelId: model_id,
|
||||||
transcript: text,
|
transcript: text,
|
||||||
voice: {
|
voice: {
|
||||||
@@ -1363,8 +1363,16 @@ const synthCartesia = async(logger, {
|
|||||||
sampleRate
|
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 {
|
return {
|
||||||
audioContent: Buffer.from(mp3),
|
audioContent: audioBuffer,
|
||||||
extension: 'mp3',
|
extension: 'mp3',
|
||||||
sampleRate
|
sampleRate
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -716,7 +716,7 @@ test('Cartesia speech synth tests', async(t) => {
|
|||||||
text,
|
text,
|
||||||
renderForCaching: true
|
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) {
|
} catch (err) {
|
||||||
console.error(JSON.stringify(err));
|
console.error(JSON.stringify(err));
|
||||||
|
|||||||
Reference in New Issue
Block a user