Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
xquanluu committed Nov 5, 2023
1 parent f2ab093 commit 6f11ed9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 10 additions & 0 deletions lib/models/speech-credential.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ class SpeechCredential extends Model {
return rows;
}

static async getSPeechCredentialsForAccount(account_sid) {
const sql = `SELECT *
FROM speech_credentials
WHERE account_sid = ? OR (account_sid is NULL AND service_provider_sid =
(SELECT service_provider_sid from accounts where account_sid = ?))`;

const [rows] = await promisePool.query(sql, [account_sid, account_sid]);
return rows;
}

static async disableStt(account_sid) {
await promisePool.execute('UPDATE speech_credentials SET use_for_stt = 0 WHERE account_sid = ?', [account_sid]);
}
Expand Down
9 changes: 5 additions & 4 deletions lib/routes/api/tts-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ const validateTtsRequestBody = async(body, logger) => {
};


const getSpeechCredential = (credentials) => {
const getSpeechCredential = (credentials, vendor, label) => {
for (const credential of credentials) {
if (credential.use_for_tts && credential.tts_tested_ok) {
if (credential.use_for_tts && credential.tts_tested_ok &&
credential.vendor === vendor && credential.label === label) {
const { vendor } = credential;
if ('google' === vendor) {
const cred = JSON.parse(credential.service_key.replace(/\n/g, '\\n'));
Expand Down Expand Up @@ -177,11 +178,11 @@ router.post('/Synthesize', async(req, res) => {
if (!result || result.length === 0) {
throw new DbErrorBadRequest(`Account not found for sid ${accountSid}`);
}
if (result[0].is_active) {
if (!result[0].is_active) {
throw new DbErrorBadRequest(`Account not active for sid ${accountSid}`);
}

const speechCreds = await SpeechCredential.getSpeechCredentialsByVendorAndLabel(null, accountSid, vendor, label);
const speechCreds = await SpeechCredential.getSPeechCredentialsForAccount(accountSid);
if (!speechCreds || speechCreds.length === 0) {
throw new
DbErrorBadRequest(`There is no available speech credential for ${vendor}${label ? ` and ${label}` : ''}`);
Expand Down

0 comments on commit 6f11ed9

Please sign in to comment.