Skip to content

Commit

Permalink
support deepgram onpremise
Browse files Browse the repository at this point in the history
  • Loading branch information
xquanluu committed Jul 31, 2024
1 parent b921cab commit 6a93a52
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
7 changes: 5 additions & 2 deletions lib/routes/api/speech-credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const encryptCredential = (obj) => {
nuance_stt_uri,
deepgram_stt_uri,
deepgram_stt_use_tls,
deepgram_tts_uri,
use_custom_tts,
custom_tts_endpoint,
custom_tts_endpoint_url,
Expand Down Expand Up @@ -204,10 +205,10 @@ const encryptCredential = (obj) => {

case 'deepgram':
// API key is optional if onprem
if (!deepgram_stt_uri) {
if (!deepgram_stt_uri || !deepgram_tts_uri) {
assert(api_key, 'invalid deepgram speech credential: api_key is required');
}
const deepgramData = JSON.stringify({api_key, deepgram_stt_uri, deepgram_stt_use_tls});
const deepgramData = JSON.stringify({api_key, deepgram_stt_uri, deepgram_stt_use_tls, deepgram_tts_uri});
return encrypt(deepgramData);

case 'ibm':
Expand Down Expand Up @@ -458,6 +459,7 @@ router.put('/:sid', async(req, res) => {
options,
deepgram_stt_uri,
deepgram_stt_use_tls,
deepgram_tts_uri,
engine_version
} = req.body;

Expand Down Expand Up @@ -485,6 +487,7 @@ router.put('/:sid', async(req, res) => {
options,
deepgram_stt_uri,
deepgram_stt_use_tls,
deepgram_tts_uri,
engine_version
};
logger.info({o, newCred}, 'updating speech credential with this new credential');
Expand Down
20 changes: 13 additions & 7 deletions lib/utils/speech-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ const testGoogleStt = async(logger, credentials) => {
};

const testDeepgramStt = async(logger, credentials) => {
const {api_key} = credentials;
const deepgram = new Deepgram(api_key);
const {api_key, deepgram_stt_uri, deepgram_stt_use_tls} = credentials;
const deepgram = new Deepgram(api_key, deepgram_stt_uri, deepgram_stt_uri && deepgram_stt_use_tls);

const mimetype = 'audio/wav';
const source = {
Expand Down Expand Up @@ -272,7 +272,8 @@ const testPlayHT = async(logger, synthAudio, credentials) => {
credentials,
language: 'en-US',
voice: 's3://voice-cloning-zero-shot/d9ff78ba-d016-47f6-b0ef-dd630f59414e/female-cs/manifest.json',
text: 'Hi there and welcome to jambones!'
text: 'Hi there and welcome to jambones!',
renderForCaching: true
}
);
// Test if playHT can fetch voices
Expand All @@ -295,7 +296,8 @@ const testRimelabs = async(logger, synthAudio, credentials) => {
credentials,
language: 'en-US',
voice: 'amber',
text: 'Hi there and welcome to jambones!'
text: 'Hi there and welcome to jambones!',
renderForCaching: true
}
);
} catch (err) {
Expand All @@ -312,7 +314,8 @@ const testWhisper = async(logger, synthAudio, credentials) => {
credentials,
language: 'en-US',
voice: 'alloy',
text: 'Hi there and welcome to jambones!'
text: 'Hi there and welcome to jambones!',
renderForCaching: true
}
);
} catch (err) {
Expand All @@ -328,7 +331,8 @@ const testDeepgramTTS = async(logger, synthAudio, credentials) => {
vendor: 'deepgram',
credentials,
model: 'aura-asteria-en',
text: 'Hi there and welcome to jambones!'
text: 'Hi there and welcome to jambones!',
renderForCaching: true
}
);
} catch (err) {
Expand Down Expand Up @@ -383,7 +387,8 @@ const testVerbioTts = async(logger, synthAudio, credentials) => {
credentials,
language: 'en-US',
voice: 'tommy_en-us',
text: 'Hi there and welcome to jambones!'
text: 'Hi there and welcome to jambones!',
renderForCaching: true
}
);
} catch (err) {
Expand Down Expand Up @@ -509,6 +514,7 @@ function decryptCredential(obj, credential, logger, isObscureKey = true) {
obj.api_key = isObscureKey ? obscureKey(o.api_key) : o.api_key;
obj.deepgram_stt_uri = o.deepgram_stt_uri;
obj.deepgram_stt_use_tls = o.deepgram_stt_use_tls;
obj.deepgram_tts_uri = o.deepgram_tts_uri;
}
else if ('ibm' === obj.vendor) {
const o = JSON.parse(decrypt(credential));
Expand Down
8 changes: 6 additions & 2 deletions test/speech-credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ test('speech credentials tests', async(t) => {
vendor: 'deepgram',
use_for_stt: true,
deepgram_stt_uri: "127.0.0.1:50002",
deepgram_stt_use_tls: true
deepgram_stt_use_tls: true,
deepgram_tts_uri: 'https://server.com'
}
});
t.ok(result.statusCode === 201, 'successfully added speech credential for deepgram');
Expand All @@ -386,6 +387,7 @@ test('speech credentials tests', async(t) => {
t.ok(result.statusCode === 200, 'successfully get speech credential for deepgram');
t.ok(result.body.deepgram_stt_uri === '127.0.0.1:50002', "deepgram_stt_uri is correct for deepgram");
t.ok(result.body.deepgram_stt_use_tls === true, "deepgram_stt_use_tls is correct for deepgram");
t.ok(result.body.deepgram_tts_uri === 'https://server.com', "deepgram_tts_uri is correct for deepgram")

result = await request.put(`/Accounts/${account_sid}/SpeechCredentials/${dg_sid}`, {
resolveWithFullResponse: true,
Expand All @@ -395,7 +397,8 @@ test('speech credentials tests', async(t) => {
vendor: 'deepgram',
use_for_stt: true,
deepgram_stt_uri: "127.0.0.2:50002",
deepgram_stt_use_tls: false
deepgram_stt_use_tls: false,
deepgram_tts_uri: 'https://server2.com'
}
});
t.ok(result.statusCode === 204, 'successfully updated speech credential for deepgram onprem');
Expand All @@ -409,6 +412,7 @@ test('speech credentials tests', async(t) => {
t.ok(result.statusCode === 200, 'successfully get speech credential for deepgram onprem');
t.ok(result.body.deepgram_stt_uri === '127.0.0.2:50002', "deepgram_stt_uri is correct for deepgram onprem");
t.ok(result.body.deepgram_stt_use_tls === false, "deepgram_stt_use_tls is correct for deepgram onprem");
t.ok(result.body.deepgram_tts_uri === 'https://server2.com', "deepgram_tts_uri is correct for deepgram onprem");

result = await request.delete(`/Accounts/${account_sid}/SpeechCredentials/${dg_sid}`, {
auth: authUser,
Expand Down

0 comments on commit 6a93a52

Please sign in to comment.