Skip to content

Commit

Permalink
Fix/getvoicelanguage (#242)
Browse files Browse the repository at this point in the history
* fix fetch eleven voice and language

* fix elevenlabs voice and language

* fix

* fix

* fix

* fix

* fix

* fix
  • Loading branch information
xquanluu authored Oct 20, 2023
1 parent bf9ae3b commit a1c302f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
5 changes: 3 additions & 2 deletions lib/models/speech-credential.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ class SpeechCredential extends Model {
static async getSpeechCredentialsByVendorAndLabel(service_provider_sid, account_sid, vendor, label) {
let sql;
if (account_sid) {
sql = 'SELECT * FROM speech_credentials WHERE account_sid = ? AND vendor = ? AND label = ?';
sql = `SELECT * FROM speech_credentials WHERE account_sid = ? AND vendor = ? ${label ? 'AND label = ?' : ''}`;
} else {
sql = 'SELECT * FROM speech_credentials WHERE service_provider_sid = ? AND vendor = ? AND label = ?';
sql = `SELECT * FROM speech_credentials WHERE service_provider_sid = ? AND vendor = ?
${label ? 'AND label = ?' : ''}`;
}
const [rows] = await promisePool.query(sql, [account_sid ? account_sid : service_provider_sid, vendor, label]);
return rows;
Expand Down
24 changes: 18 additions & 6 deletions lib/routes/api/speech-credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,8 @@ router.post('/languages', async(req, res) => {
const getTtsVoices = async(vendor, label, service_provider_sid, account_sid) => {
const credentials = await SpeechCredential.getSpeechCredentialsByVendorAndLabel(
service_provider_sid, account_sid, vendor, label);
const cred = credentials && credentials.length > 0 ? credentials[0] : null;
const tmp = credentials && credentials.length > 0 ? credentials[0] : null;
const cred = tmp ? JSON.parse(decrypt(tmp.credential)) : null;
if (vendor === 'elevenlabs') {
const get = bent('https://api.elevenlabs.io', 'GET', 'json', {
...(cred && {
Expand All @@ -808,20 +809,31 @@ const getTtsVoices = async(vendor, label, service_provider_sid, account_sid) =>
});
const resp = await get('/v1/voices');
return resp ? resp.voices.map((v) => {
let name = `${v.name}${v.category !== 'premade' ? ` (${v.category})` : ''} -
${v.labels.accent ? ` ${v.labels.accent},` : ''}
${v.labels.description ? ` ${v.labels.description},` : ''}
${v.labels.age ? ` ${v.labels.age},` : ''}
${v.labels.gender ? ` ${v.labels.gender},` : ''}
${v.labels['use case'] ? ` ${v.labels['use case']},` : ''}
`;
const lastIndex = name.lastIndexOf(',');
if (lastIndex !== -1) {
name = name.substring(0, lastIndex);
}
return {
value: v.voice_id,
name: `${v.name} - ${v.labels.accent}, ${v.labels.description},
${v.labels.age}, ${v.labels.gender}, ${v.labels['use case']}`
name
};
}) : [];
}).sort((a, b) => a.name.localeCompare(b.name)) : [];
}
return [];
};

const getTtsLanguages = async(vendor, label, service_provider_sid, account_sid) => {
const credentials = await SpeechCredential.getSpeechCredentialsByVendorAndLabel(
service_provider_sid, account_sid, vendor, label);
const cred = credentials && credentials.length > 0 ? credentials[0] : null;
const tmp = credentials && credentials.length > 0 ? credentials[0] : null;
const cred = tmp ? JSON.parse(decrypt(tmp.credential)) : null;
if (vendor === 'elevenlabs') {
if (!cred) {
return [];
Expand All @@ -839,7 +851,7 @@ const getTtsLanguages = async(vendor, label, service_provider_sid, account_sid)
value: l.language_id,
name: l.name
};
}) : [];
}).sort((a, b) => a.name.localeCompare(b.name)) : [];
}
};

Expand Down

0 comments on commit a1c302f

Please sign in to comment.