@jambonz/speech-utils 0.2.25 → 0.2.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ jobs:
11
11
  - uses: actions/checkout@v4
12
12
  - uses: actions/setup-node@v4
13
13
  with:
14
- node-version: lts/*
14
+ node-version: '20'
15
15
  - run: npm install
16
16
  - name: Install Docker Compose
17
17
  run: |
@@ -1316,6 +1316,7 @@ const synthCartesia = async(logger, {
1316
1316
  if (embedding) params += `,embedding=${embedding}`;
1317
1317
  if (opts.speed) params += `,speed=${opts.speed}`;
1318
1318
  if (opts.emotion) params += `,emotion=${opts.emotion}`;
1319
+ if (opts.volume) params += `,volume=${opts.volume}`;
1319
1320
  params += '}';
1320
1321
 
1321
1322
  return {
@@ -1328,7 +1329,7 @@ const synthCartesia = async(logger, {
1328
1329
  try {
1329
1330
  const client = new CartesiaClient({ apiKey: api_key });
1330
1331
  const sampleRate = 48000;
1331
- const mp3 = await client.tts.bytes({
1332
+ const mp3Stream = await client.tts.bytes({
1332
1333
  modelId: model_id,
1333
1334
  transcript: text,
1334
1335
  voice: {
@@ -1341,13 +1342,20 @@ const synthCartesia = async(logger, {
1341
1342
  id: voice
1342
1343
  }
1343
1344
  ),
1344
- ...(opts.speed || opts.emotion && {
1345
+ ...(model_id === 'sonic-2' && (opts.speed || opts.emotion) && {
1345
1346
  experimentalControls: {
1346
1347
  ...(opts.speed !== null && opts.speed !== undefined && {speed: opts.speed}),
1347
- ...(opts.emotion && {emotion: opts.emotion}),
1348
+ ...(opts.emotion && {emotion: [opts.emotion]}),
1348
1349
  }
1349
- })
1350
+ }),
1350
1351
  },
1352
+ ...(model_id === 'sonic-3' && (opts.speed || opts.emotion || opts.volume) && {
1353
+ generationConfig: {
1354
+ ...(opts.volume !== null && opts.volume !== undefined && {volume: opts.volume}),
1355
+ ...(opts.speed !== null && opts.speed !== undefined && {speed: opts.speed}),
1356
+ ...(opts.emotion !== null && opts.emotion !== undefined && {emotion: opts.emotion}),
1357
+ }
1358
+ }),
1351
1359
  language: language,
1352
1360
  outputFormat: {
1353
1361
  container: 'mp3',
@@ -1355,8 +1363,16 @@ const synthCartesia = async(logger, {
1355
1363
  sampleRate
1356
1364
  },
1357
1365
  });
1366
+
1367
+ // bytes() returns a ReadableStream - collect all chunks
1368
+ const chunks = [];
1369
+ for await (const chunk of mp3Stream) {
1370
+ chunks.push(chunk);
1371
+ }
1372
+ const audioBuffer = Buffer.concat(chunks);
1373
+
1358
1374
  return {
1359
- audioContent: Buffer.from(mp3),
1375
+ audioContent: audioBuffer,
1360
1376
  extension: 'mp3',
1361
1377
  sampleRate
1362
1378
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jambonz/speech-utils",
3
- "version": "0.2.25",
3
+ "version": "0.2.27",
4
4
  "description": "TTS-related speech utilities for jambonz",
5
5
  "main": "index.js",
6
6
  "author": "Dave Horton",
@@ -29,7 +29,7 @@
29
29
  "23": "^0.0.0",
30
30
  "@aws-sdk/client-polly": "^3.496.0",
31
31
  "@aws-sdk/client-sts": "^3.496.0",
32
- "@cartesia/cartesia-js": "^2.1.0",
32
+ "@cartesia/cartesia-js": "^2.2.7",
33
33
  "@google-cloud/text-to-speech": "^5.5.0",
34
34
  "@grpc/grpc-js": "^1.9.14",
35
35
  "@jambonz/realtimedb-helpers": "^0.8.7",
package/test/synth.js CHANGED
@@ -716,7 +716,7 @@ test('Cartesia speech synth tests', async(t) => {
716
716
  text,
717
717
  renderForCaching: true
718
718
  });
719
- t.ok(!opts.servedFromCache, `successfully playht eleven audio to ${opts.filePath}`);
719
+ t.ok(!opts.servedFromCache, `successfully cartesia eleven audio to ${opts.filePath}`);
720
720
 
721
721
  } catch (err) {
722
722
  console.error(JSON.stringify(err));