mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-01-25 02:08:24 +00:00
Fix/getvoicelanguage (#242)
* fix fetch eleven voice and language * fix elevenlabs voice and language * fix * fix * fix * fix * fix * fix
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 && {
|
||||
@@ -808,12 +809,22 @@ 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 [];
|
||||
};
|
||||
@@ -821,7 +832,8 @@ const getTtsVoices = async(vendor, label, service_provider_sid, account_sid) =>
|
||||
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 [];
|
||||
@@ -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)) : [];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user