@jambonz/speech-utils 0.0.27 → 0.0.29
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.
- package/lib/get-aws-sts-token.js +8 -7
- package/lib/synth-audio.js +10 -6
- package/package.json +1 -1
- package/test/synth.js +10 -1
package/lib/get-aws-sts-token.js
CHANGED
|
@@ -14,13 +14,14 @@ async function getAwsAuthToken(
|
|
|
14
14
|
if (obj) return {...obj, servedFromCache: true};
|
|
15
15
|
|
|
16
16
|
/* access token not found in cache, so generate it using STS */
|
|
17
|
-
const stsClient = new STSClient({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
const stsClient = new STSClient({
|
|
18
|
+
region: awsRegion,
|
|
19
|
+
credentials: {
|
|
20
|
+
accessKeyId: awsAccessKeyId,
|
|
21
|
+
secretAccessKey: awsSecretAccessKey,
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const command = new GetSessionTokenCommand({DurationSeconds: EXPIRY});
|
|
24
25
|
const data = await stsClient.send(command);
|
|
25
26
|
|
|
26
27
|
const credentials = {
|
package/lib/synth-audio.js
CHANGED
|
@@ -76,7 +76,7 @@ const trimTrailingSilence = (buffer) => {
|
|
|
76
76
|
* the synthesized audio, and a variable indicating whether it was served from cache
|
|
77
77
|
*/
|
|
78
78
|
async function synthAudio(client, logger, stats, { account_sid,
|
|
79
|
-
vendor, language, voice, gender, text, engine, salt, model, credentials, deploymentId, disableTtsCache
|
|
79
|
+
vendor, language, voice, gender, text, engine, salt, model, credentials, deploymentId, disableTtsCache, options
|
|
80
80
|
}) {
|
|
81
81
|
let audioBuffer;
|
|
82
82
|
let servedFromCache = false;
|
|
@@ -194,7 +194,7 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|
|
194
194
|
audioBuffer = await synthWellSaid(logger, {credentials, stats, language, voice, text, filePath});
|
|
195
195
|
break;
|
|
196
196
|
case 'elevenlabs':
|
|
197
|
-
audioBuffer = await synthElevenlabs(logger, {credentials, stats, language, voice, text, filePath});
|
|
197
|
+
audioBuffer = await synthElevenlabs(logger, {credentials, options, stats, language, voice, text, filePath});
|
|
198
198
|
break;
|
|
199
199
|
case 'whisper':
|
|
200
200
|
audioBuffer = await synthWhisper(logger, {credentials, stats, voice, text});
|
|
@@ -585,21 +585,25 @@ const synthCustomVendor = async(logger, {credentials, stats, language, voice, te
|
|
|
585
585
|
}
|
|
586
586
|
};
|
|
587
587
|
|
|
588
|
-
const synthElevenlabs = async(logger, {credentials, stats, language, voice, text}) => {
|
|
589
|
-
const {api_key, model_id} = credentials;
|
|
588
|
+
const synthElevenlabs = async(logger, {credentials, options, stats, language, voice, text}) => {
|
|
589
|
+
const {api_key, model_id, options: credOpts} = credentials;
|
|
590
|
+
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
|
591
|
+
const optimize_streaming_latency = opts.optimize_streaming_latency ?
|
|
592
|
+
`?optimize_streaming_latency=${opts.optimize_streaming_latency}` : '';
|
|
590
593
|
try {
|
|
591
594
|
const post = bent('https://api.elevenlabs.io', 'POST', 'buffer', {
|
|
592
595
|
'xi-api-key': api_key,
|
|
593
596
|
'Accept': 'audio/mpeg',
|
|
594
597
|
'Content-Type': 'application/json'
|
|
595
598
|
});
|
|
596
|
-
const mp3 = await post(`/v1/text-to-speech/${voice}`, {
|
|
599
|
+
const mp3 = await post(`/v1/text-to-speech/${voice}${optimize_streaming_latency}`, {
|
|
597
600
|
text,
|
|
598
601
|
model_id,
|
|
599
602
|
voice_settings: {
|
|
600
603
|
stability: 0.5,
|
|
601
604
|
similarity_boost: 0.5
|
|
602
|
-
}
|
|
605
|
+
},
|
|
606
|
+
...opts
|
|
603
607
|
});
|
|
604
608
|
return mp3;
|
|
605
609
|
} catch (err) {
|
package/package.json
CHANGED
package/test/synth.js
CHANGED
|
@@ -459,7 +459,16 @@ test('Elevenlabs speech synth tests', async(t) => {
|
|
|
459
459
|
vendor: 'elevenlabs',
|
|
460
460
|
credentials: {
|
|
461
461
|
api_key: process.env.ELEVENLABS_API_KEY,
|
|
462
|
-
model_id: process.env.ELEVENLABS_MODEL_ID
|
|
462
|
+
model_id: process.env.ELEVENLABS_MODEL_ID,
|
|
463
|
+
options: JSON.stringify({
|
|
464
|
+
optimize_streaming_latency: 1,
|
|
465
|
+
voice_settings: {
|
|
466
|
+
similarity_boost: 1,
|
|
467
|
+
stability: 0.8,
|
|
468
|
+
style: 1,
|
|
469
|
+
use_speaker_boost: true
|
|
470
|
+
}
|
|
471
|
+
})
|
|
463
472
|
},
|
|
464
473
|
language: 'en-US',
|
|
465
474
|
voice: process.env.ELEVENLABS_VOICE_ID,
|