mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-01-25 02:08:24 +00:00
support elevenlabs different endpoint (#502)
* support elevenlabs different endpoint * wip * wip * wip
This commit is contained in:
@@ -162,6 +162,7 @@ const encryptCredential = (obj) => {
|
||||
voice_engine,
|
||||
engine_version,
|
||||
service_version,
|
||||
api_uri,
|
||||
options
|
||||
} = obj;
|
||||
|
||||
@@ -265,7 +266,11 @@ const encryptCredential = (obj) => {
|
||||
case 'elevenlabs':
|
||||
assert(api_key, 'invalid elevenLabs speech credential: api_key is required');
|
||||
assert(model_id, 'invalid elevenLabs speech credential: model_id is required');
|
||||
const elevenlabsData = JSON.stringify({api_key, model_id, options});
|
||||
const elevenlabsData = JSON.stringify({
|
||||
api_key,
|
||||
model_id,
|
||||
...(api_uri && {api_uri}),
|
||||
options});
|
||||
return encrypt(elevenlabsData);
|
||||
|
||||
case 'speechmatics':
|
||||
@@ -537,7 +542,8 @@ router.put('/:sid', async(req, res) => {
|
||||
service_version,
|
||||
speechmatics_stt_uri,
|
||||
resemble_tts_use_tls,
|
||||
resemble_tts_uri
|
||||
resemble_tts_uri,
|
||||
api_uri
|
||||
} = req.body;
|
||||
|
||||
const newCred = {
|
||||
@@ -572,7 +578,8 @@ router.put('/:sid', async(req, res) => {
|
||||
service_version,
|
||||
speechmatics_stt_uri,
|
||||
resemble_tts_uri,
|
||||
resemble_tts_use_tls
|
||||
resemble_tts_use_tls,
|
||||
api_uri
|
||||
};
|
||||
logger.info({o, newCred}, 'updating speech credential with this new credential');
|
||||
obj.credential = encryptCredential(newCred);
|
||||
@@ -865,10 +872,10 @@ router.get('/:sid/test', async(req, res) => {
|
||||
}
|
||||
}
|
||||
} else if (cred.vendor === 'elevenlabs') {
|
||||
const {api_key, model_id} = credential;
|
||||
const {api_key, model_id, api_uri} = credential;
|
||||
if (cred.use_for_tts) {
|
||||
try {
|
||||
await testElevenlabs(logger, {api_key, model_id});
|
||||
await testElevenlabs(logger, {api_key, model_id, api_uri});
|
||||
results.tts.status = 'ok';
|
||||
SpeechCredential.ttsTestResult(sid, true);
|
||||
} catch (err) {
|
||||
|
||||
@@ -316,8 +316,8 @@ const testWellSaidTts = async(logger, credentials) => {
|
||||
};
|
||||
|
||||
const testElevenlabs = async(logger, credentials) => {
|
||||
const {api_key, model_id} = credentials;
|
||||
const response = await fetch('https://api.elevenlabs.io/v1/text-to-speech/21m00Tcm4TlvDq8ikWAM', {
|
||||
const {api_key, model_id, api_uri} = credentials;
|
||||
const response = await fetch(`https://${api_uri || 'api.elevenlabs.io'}/v1/text-to-speech/21m00Tcm4TlvDq8ikWAM`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'xi-api-key': api_key,
|
||||
@@ -714,6 +714,7 @@ function decryptCredential(obj, credential, logger, isObscureKey = true) {
|
||||
const o = JSON.parse(decrypt(credential));
|
||||
obj.api_key = isObscureKey ? obscureKey(o.api_key) : o.api_key;
|
||||
obj.model_id = o.model_id;
|
||||
obj.api_uri = o.api_uri;
|
||||
obj.options = o.options;
|
||||
} else if ('playht' === obj.vendor) {
|
||||
const o = JSON.parse(decrypt(credential));
|
||||
@@ -1014,10 +1015,12 @@ async function getLanguagesVoicesForElevenlabs(credential) {
|
||||
'xi-api-key': credential.api_key
|
||||
};
|
||||
|
||||
const getModelPromise = fetch('https://api.elevenlabs.io/v1/models', {
|
||||
const api_uri = credential.api_uri || 'api.elevenlabs.io';
|
||||
|
||||
const getModelPromise = fetch(`https://${api_uri}/v1/models`, {
|
||||
headers
|
||||
});
|
||||
const getVoicePromise = fetch('https://api.elevenlabs.io/v1/voices', {
|
||||
const getVoicePromise = fetch(`https://${api_uri}/v1/voices`, {
|
||||
headers
|
||||
});
|
||||
const [langResp, voiceResp] = await Promise.all([getModelPromise, getVoicePromise]);
|
||||
|
||||
Reference in New Issue
Block a user