mirror of
https://github.com/jambonz/speech-utils.git
synced 2026-10-03 23:33:59 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12a121672d | ||
|
|
7b94a5a969 |
+80
-13
@@ -80,7 +80,7 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
||||
logger = logger || noopLogger;
|
||||
|
||||
assert.ok(['google', 'aws', 'polly', 'microsoft', 'wellsaid', 'nvidia', 'elevenlabs',
|
||||
'whisper', 'deepgram', 'rimelabs', 'cartesia', 'inworld', 'resemble'].includes(vendor) ||
|
||||
'whisper', 'deepgram', 'rimelabs', 'cartesia', 'inworld', 'resemble', 'murf'].includes(vendor) ||
|
||||
vendor.startsWith('custom'),
|
||||
`synthAudio supported vendors are google, aws, microsoft, nvidia and wellsaid ..etc, not ${vendor}`);
|
||||
if ('google' === vendor) {
|
||||
@@ -96,8 +96,7 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
||||
else if ('nvidia' === vendor) {
|
||||
assert.ok(voice, 'synthAudio requires voice when nvidia is used');
|
||||
assert.ok(language, 'synthAudio requires language when nvidia is used');
|
||||
assert.ok(credentials.riva_server_uri || credentials.api_key,
|
||||
'synthAudio requires riva_server_uri (self-hosted) or api_key (NVCF cloud) in credentials when nvidia is used');
|
||||
assert.ok(credentials.riva_server_uri, 'synthAudio requires riva_server_uri in credentials when nvidia is used');
|
||||
}
|
||||
else if ('wellsaid' === vendor) {
|
||||
language = 'en-US'; // WellSaid only supports English atm
|
||||
@@ -128,6 +127,9 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
||||
} else if ('cartesia' === vendor) {
|
||||
assert.ok(credentials.api_key, 'synthAudio requires api_key when cartesia is used');
|
||||
assert.ok(credentials.model_id, 'synthAudio requires model_id when cartesia is used');
|
||||
} else if ('murf' === vendor) {
|
||||
assert.ok(voice, 'synthAudio requires voice when murf is used');
|
||||
assert.ok(credentials.api_key, 'synthAudio requires api_key when murf is used');
|
||||
} else if (vendor === 'resemble') {
|
||||
assert.ok(voice, 'synthAudio requires voice when resemble is used');
|
||||
assert.ok(credentials.api_key, 'synthAudio requires api_key when resemble is used');
|
||||
@@ -212,6 +214,11 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
||||
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming,
|
||||
disableTtsCache});
|
||||
break;
|
||||
case 'murf':
|
||||
audioData = await synthMurf(logger, {
|
||||
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming,
|
||||
disableTtsCache});
|
||||
break;
|
||||
case 'whisper':
|
||||
audioData = await synthWhisper(logger, {
|
||||
credentials, stats, voice, key, text, instructions, renderForCaching, disableTtsStreaming,
|
||||
@@ -683,16 +690,10 @@ const synthWellSaid = async(logger, {credentials, stats, language, voice, gender
|
||||
const synthNvidia = async(client, logger, {
|
||||
credentials, stats, language, voice, model, key, text, renderForCaching, disableTtsStreaming, disableTtsCache
|
||||
}) => {
|
||||
const {riva_server_uri, api_key, function_id} = credentials;
|
||||
const {riva_server_uri} = credentials;
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '{';
|
||||
if (api_key) {
|
||||
/* NVCF cloud: mediajam connects to grpc.nvcf.nvidia.com using these */
|
||||
params += `NVIDIA_API_KEY=${api_key}`;
|
||||
if (function_id) params += `,NVIDIA_FUNCTION_ID=${function_id}`;
|
||||
} else {
|
||||
params += `riva_server_uri=${riva_server_uri}`;
|
||||
}
|
||||
let params = '';
|
||||
params += `{riva_server_uri=${riva_server_uri}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,voice=${voice}`;
|
||||
params += `,language=${language}`;
|
||||
@@ -708,7 +709,7 @@ const synthNvidia = async(client, logger, {
|
||||
let rivaClient, request;
|
||||
const sampleRate = 8000;
|
||||
try {
|
||||
rivaClient = await createRivaClient(riva_server_uri, {apiKey: api_key, functionId: function_id});
|
||||
rivaClient = await createRivaClient(riva_server_uri);
|
||||
request = new SynthesizeSpeechRequest();
|
||||
request.setVoiceName(voice);
|
||||
request.setLanguageCode(language);
|
||||
@@ -976,6 +977,72 @@ const synthRimelabs = async(logger, {
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
const synthMurf = async(logger, {
|
||||
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming, disableTtsCache
|
||||
}) => {
|
||||
const {api_key, model_id, api_uri, options: credOpts} = credentials;
|
||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||
|
||||
/* default to using the streaming interface, unless disabled by env var OR we want just a cache file */
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
/* param keys here must match mod_murf_tts's text_param handler */
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += ',vendor=murf';
|
||||
params += `,voice=${voice}`;
|
||||
if (model_id) params += `,model_id=${model_id}`;
|
||||
if (language) params += `,language=${language}`;
|
||||
if (api_uri) params += `,api_uri=${api_uri}`;
|
||||
if (opts.style) params += `,style=${opts.style}`;
|
||||
if (opts.rate !== undefined && opts.rate !== null) params += `,rate=${opts.rate}`;
|
||||
if (opts.pitch !== undefined && opts.pitch !== null) params += `,pitch=${opts.pitch}`;
|
||||
if (opts.variation !== undefined && opts.variation !== null) params += `,variation=${opts.variation}`;
|
||||
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||
params += '}';
|
||||
|
||||
return {
|
||||
filePath: `say:${params}${text.replace(/\n/g, ' ').replace(/\r/g, ' ')}`,
|
||||
servedFromCache: false,
|
||||
rtt: 0
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const sampleRate = 8000;
|
||||
/* no Accept header: murf returns 406 if it doesn't match; the response
|
||||
container is selected by the `format` field in the body instead */
|
||||
const post = bent(api_uri || 'https://global.api.murf.ai', 'POST', 'buffer', {
|
||||
'api-key': api_key,
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
/* murf REST schema is documented loosely; field names follow the SDK params
|
||||
(voice_id/model/format/sample_rate) plus the websocket voice fields. */
|
||||
const audioContent = await post('/v1/speech/stream', {
|
||||
text,
|
||||
voice_id: voice,
|
||||
...(model_id && {model: model_id}),
|
||||
...(language && {locale: language}),
|
||||
...(opts.style && {style: opts.style}),
|
||||
...(opts.rate !== undefined && opts.rate !== null && {rate: opts.rate}),
|
||||
...(opts.pitch !== undefined && opts.pitch !== null && {pitch: opts.pitch}),
|
||||
...(opts.variation !== undefined && opts.variation !== null && {variation: opts.variation}),
|
||||
format: 'WAV',
|
||||
sample_rate: sampleRate,
|
||||
channel_type: 'MONO'
|
||||
});
|
||||
return {
|
||||
audioContent,
|
||||
extension: 'wav',
|
||||
sampleRate
|
||||
};
|
||||
} catch (err) {
|
||||
logger.info({err}, 'synth murf returned error');
|
||||
stats.increment('tts.count', ['vendor:murf', 'accepted:no']);
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
const synthWhisper = async(logger, {credentials, stats, voice, key, text, instructions,
|
||||
renderForCaching, disableTtsStreaming, disableTtsCache}) => {
|
||||
const {api_key, model_id, baseURL, timeout, speed} = credentials;
|
||||
|
||||
+3
-18
@@ -38,24 +38,9 @@ function makeAwsKey(awsAccessKeyId) {
|
||||
return `aws:${hash.digest('hex')}`;
|
||||
}
|
||||
|
||||
// NVCF cloud TTS function-id default: ai-magpie-tts-multilingual (public)
|
||||
const NVIDIA_TTS_FUNCTION_ID = '877104f7-e885-42b9-8de8-f6e4c6303969';
|
||||
|
||||
const createRivaClient = async(rivaUri, {apiKey, functionId} = {}) => {
|
||||
if (apiKey) {
|
||||
/* NVCF cloud: TLS to grpc.nvcf.nvidia.com:443 with per-RPC metadata
|
||||
(function-id + Bearer api key) baked into the channel credentials */
|
||||
const callCreds = grpc.credentials.createFromMetadataGenerator((_params, cb) => {
|
||||
const md = new grpc.Metadata();
|
||||
md.add('function-id', functionId || NVIDIA_TTS_FUNCTION_ID);
|
||||
md.add('authorization', `Bearer ${apiKey}`);
|
||||
cb(null, md);
|
||||
});
|
||||
const creds = grpc.credentials.combineChannelCredentials(
|
||||
grpc.credentials.createSsl(), callCreds);
|
||||
return new RivaSpeechSynthesisClient('grpc.nvcf.nvidia.com:443', creds);
|
||||
}
|
||||
return new RivaSpeechSynthesisClient(rivaUri, grpc.credentials.createInsecure());
|
||||
const createRivaClient = async(rivaUri) => {
|
||||
const client = new RivaSpeechSynthesisClient(rivaUri, grpc.credentials.createInsecure());
|
||||
return client;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@jambonz/speech-utils",
|
||||
"version": "1.0.6",
|
||||
"version": "1.0.7",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@jambonz/speech-utils",
|
||||
"version": "1.0.6",
|
||||
"version": "1.0.7",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"23": "^0.0.0",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@jambonz/speech-utils",
|
||||
"version": "1.0.6",
|
||||
"version": "1.0.7",
|
||||
"description": "TTS-related speech utilities for jambonz",
|
||||
"main": "index.js",
|
||||
"author": "Dave Horton",
|
||||
|
||||
Reference in New Issue
Block a user