mirror of
https://github.com/jambonz/speech-utils.git
synced 2026-07-23 12:41:48 +00:00
changes to support elevenlabs tts streaming
This commit is contained in:
+22
-7
@@ -194,16 +194,12 @@ async function synthAudio(client, logger, stats, { account_sid,
|
||||
audioBuffer = await synthWellSaid(logger, {credentials, stats, language, voice, text, filePath});
|
||||
break;
|
||||
case 'elevenlabs':
|
||||
if (process.env.JAMBONES_ELEVENLABS_STREAMING) {
|
||||
return {
|
||||
filePath: `say:${text}`,
|
||||
servedFromCache: false,
|
||||
rtt: 0
|
||||
};
|
||||
audioBuffer = await synthElevenlabs(logger, {credentials, options, stats, language, voice, text, filePath});
|
||||
if (typeof audioBuffer === 'object' && audioBuffer.filePath) {
|
||||
return audioBuffer;
|
||||
}
|
||||
else {
|
||||
audioBuffer = await synthElevenlabs(logger, {credentials, options, stats, language, voice, text, filePath});
|
||||
|
||||
}
|
||||
break;
|
||||
case 'whisper':
|
||||
@@ -607,6 +603,25 @@ const synthCustomVendor = async(logger, {credentials, stats, language, voice, te
|
||||
const synthElevenlabs = async(logger, {credentials, options, stats, language, voice, text}) => {
|
||||
const {api_key, model_id, options: credOpts} = credentials;
|
||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||
|
||||
if (process.env.JAMBONES_ELEVENLABS_STREAMING) {
|
||||
let params = '';
|
||||
params += `{api_key=${api_key}`;
|
||||
params += `,model_id=${model_id}`;
|
||||
params += `,optimize_streaming_latency=${opts.optimize_streaming_latency || 2}`;
|
||||
if (opts.voice_settings?.similarity_boost) params += `,similarity_boost=${opts.voice_settings.similarity_boost}`;
|
||||
if (opts.voice_settings?.stability) params += `,stability=${opts.voice_settings.stability}`;
|
||||
if (opts.voice_settings?.style) params += `,style=${opts.voice_settings.style}`;
|
||||
if (opts.voice_settings?.use_speaker_boost === false) params += ',use_speaker_boost=false';
|
||||
params += '}';
|
||||
|
||||
return {
|
||||
filePath: `say:${params}${text.replace(/\n/g, ' ')}`,
|
||||
servedFromCache: false,
|
||||
rtt: 0
|
||||
};
|
||||
}
|
||||
|
||||
const optimize_streaming_latency = opts.optimize_streaming_latency ?
|
||||
`?optimize_streaming_latency=${opts.optimize_streaming_latency}` : '';
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user