mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-07-23 20:42:16 +00:00
add support for deepgram STT
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ const sql = `
|
||||
function makeStrategy(logger, retrieveKey) {
|
||||
return new Strategy(
|
||||
async function(token, done) {
|
||||
logger.debug(`validating with token ${token}`);
|
||||
//logger.debug(`validating with token ${token}`);
|
||||
jwt.verify(token, process.env.JWT_SECRET, async(err, decoded) => {
|
||||
if (err) {
|
||||
if (err.name === 'TokenExpiredError') {
|
||||
|
||||
@@ -14,7 +14,8 @@ const {
|
||||
testMicrosoftTts,
|
||||
testWellSaidTts,
|
||||
testNuanceStt,
|
||||
testNuanceTts
|
||||
testNuanceTts,
|
||||
testDeepgramStt
|
||||
} = require('../../utils/speech-utils');
|
||||
|
||||
const obscureKey = (key) => {
|
||||
@@ -88,6 +89,11 @@ const encryptCredential = (obj) => {
|
||||
const nuanceData = JSON.stringify({client_id, secret});
|
||||
return encrypt(nuanceData);
|
||||
|
||||
case 'deepgram':
|
||||
assert(api_key, 'invalid deepgram speech credential: api_key is required');
|
||||
const deepgramData = JSON.stringify({api_key});
|
||||
return encrypt(deepgramData);
|
||||
|
||||
default:
|
||||
assert(false, `invalid or missing vendor: ${vendor}`);
|
||||
}
|
||||
@@ -175,6 +181,10 @@ router.get('/', async(req, res) => {
|
||||
obj.client_id = o.client_id;
|
||||
obj.secret = obscureKey(o.secret);
|
||||
}
|
||||
else if ('deepgram' === obj.vendor) {
|
||||
const o = JSON.parse(decrypt(credential));
|
||||
obj.api_key = obscureKey(o.api_key);
|
||||
}
|
||||
return obj;
|
||||
}));
|
||||
} catch (err) {
|
||||
@@ -225,6 +235,10 @@ router.get('/:sid', async(req, res) => {
|
||||
obj.client_id = o.client_id;
|
||||
obj.secret = obscureKey(o.secret);
|
||||
}
|
||||
else if ('deepgram' === obj.vendor) {
|
||||
const o = JSON.parse(decrypt(credential));
|
||||
obj.api_key = obscureKey(o.api_key);
|
||||
}
|
||||
res.status(200).json(obj);
|
||||
} catch (err) {
|
||||
sysError(logger, res, err);
|
||||
@@ -474,6 +488,19 @@ router.get('/:sid/test', async(req, res) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (cred.vendor === 'deepgram') {
|
||||
const {api_key} = credential;
|
||||
if (cred.use_for_stt) {
|
||||
try {
|
||||
await testDeepgramStt(logger, {api_key});
|
||||
results.stt.status = 'ok';
|
||||
SpeechCredential.sttTestResult(sid, true);
|
||||
} catch (err) {
|
||||
results.stt = {status: 'fail', reason: err.message};
|
||||
SpeechCredential.sttTestResult(sid, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
res.status(200).json(results);
|
||||
} catch (err) {
|
||||
sysError(logger, res, err);
|
||||
|
||||
@@ -2,6 +2,7 @@ const ttsGoogle = require('@google-cloud/text-to-speech');
|
||||
const sttGoogle = require('@google-cloud/speech').v1p1beta1;
|
||||
const Polly = require('aws-sdk/clients/polly');
|
||||
const AWS = require('aws-sdk');
|
||||
const { Deepgram } = require('@deepgram/sdk');
|
||||
const bent = require('bent');
|
||||
const fs = require('fs');
|
||||
|
||||
@@ -42,6 +43,33 @@ const testGoogleStt = async(logger, credentials) => {
|
||||
}
|
||||
};
|
||||
|
||||
const testDeepgramStt = async(logger, credentials) => {
|
||||
const {api_key} = credentials;
|
||||
const deepgram = new Deepgram(api_key);
|
||||
|
||||
const mimetype = 'audio/wav';
|
||||
const source = {
|
||||
buffer: fs.readFileSync(`${__dirname}/../../data/test_audio.wav`),
|
||||
mimetype: mimetype
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
// Send the audio to Deepgram and get the response
|
||||
deepgram.transcription
|
||||
.preRecorded(source, {punctuate: true})
|
||||
.then((response) => {
|
||||
//logger.debug({response}, 'got transcript');
|
||||
if (response?.results?.channels[0]?.alternatives?.length > 0) resolve(response);
|
||||
else reject(new Error('no transcript returned'));
|
||||
return;
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.info({err}, 'failed to get deepgram transcript');
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const testAwsTts = (logger, credentials) => {
|
||||
const polly = new Polly(credentials);
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -138,5 +166,6 @@ module.exports = {
|
||||
testMicrosoftStt,
|
||||
testWellSaidStt,
|
||||
testNuanceTts,
|
||||
testNuanceStt
|
||||
testNuanceStt,
|
||||
testDeepgramStt
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user