mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
Feature/ibm watson (#193)
* initial changes to support ibm watson * update specs.json for ibm * update to drachtio-fsmrf with support for ibm * bugfix: set access token for ibm stt, not api_key * fix name of api_key * normalize ibm transcription results * rework ibm credentials * bugfix setting runtime speech creds * bugfix: ibm region * typo * changes to transcribe for ibm watson * implement connect handler * bugfix: bind error * proper use of result_index * ibm error handling
This commit is contained in:
@@ -27,6 +27,23 @@ const normalizeDeepgram = (evt, channel, language) => {
|
||||
};
|
||||
};
|
||||
|
||||
const normalizeIbm = (evt, channel, language) => {
|
||||
const copy = JSON.parse(JSON.stringify(evt));
|
||||
//const idx = evt.result_index;
|
||||
const result = evt.results[0];
|
||||
|
||||
return {
|
||||
language_code: language,
|
||||
channel_tag: channel,
|
||||
is_final: result.final,
|
||||
alternatives: result.alternatives,
|
||||
vendor: {
|
||||
name: 'ibm',
|
||||
evt: copy
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const normalizeGoogle = (evt, channel, language) => {
|
||||
const copy = JSON.parse(JSON.stringify(evt));
|
||||
return {
|
||||
@@ -113,6 +130,8 @@ module.exports = (logger) => {
|
||||
return normalizeAws(evt, channel, language);
|
||||
case 'nuance':
|
||||
return normalizeNuance(evt, channel, language);
|
||||
case 'ibm':
|
||||
return normalizeIbm(evt, channel, language);
|
||||
default:
|
||||
logger.error(`Unknown vendor ${vendor}`);
|
||||
return evt;
|
||||
@@ -311,6 +330,31 @@ module.exports = (logger) => {
|
||||
{DEEPGRAM_SPEECH_VAD_TURNOFF: deepgramOptions.tag}
|
||||
};
|
||||
}
|
||||
else if ('ibm' === rOpts.vendor) {
|
||||
const {ibmOptions = {}} = rOpts;
|
||||
opts = {
|
||||
...opts,
|
||||
...(sttCredentials.access_token) &&
|
||||
{IBM_ACCESS_TOKEN: sttCredentials.access_token},
|
||||
...(sttCredentials.stt_region) &&
|
||||
{IBM_SPEECH_REGION: sttCredentials.stt_region},
|
||||
...(sttCredentials.instance_id) &&
|
||||
{IBM_SPEECH_INSTANCE_ID: sttCredentials.instance_id},
|
||||
...(ibmOptions.model) &&
|
||||
{IBM_SPEECH_MODEL: ibmOptions.model},
|
||||
...(ibmOptions.language_customization_id) &&
|
||||
{IBM_SPEECH_LANGUAGE_CUSTOMIZATION_ID: ibmOptions.language_customization_id},
|
||||
...(ibmOptions.acoustic_customization_id) &&
|
||||
{IBM_SPEECH_ACOUSTIC_CUSTOMIZATION_ID: ibmOptions.acoustic_customization_id},
|
||||
...(ibmOptions.baseModelVersion) &&
|
||||
{IBM_SPEECH_BASE_MODEL_VERSION: ibmOptions.baseModelVersion},
|
||||
...(ibmOptions.watsonMetadata) &&
|
||||
{IBM_SPEECH_WATSON_METADATA: ibmOptions.watsonMetadata},
|
||||
...(ibmOptions.watsonLearningOptOut) &&
|
||||
{IBM_SPEECH_WATSON_LEARNING_OPT_OUT: ibmOptions.watsonLearningOptOut}
|
||||
};
|
||||
}
|
||||
|
||||
logger.debug({opts}, 'recognizer channel vars');
|
||||
return opts;
|
||||
};
|
||||
@@ -336,12 +380,34 @@ module.exports = (logger) => {
|
||||
ep.removeCustomEventListener(DeepgramTranscriptionEvents.Transcription);
|
||||
ep.removeCustomEventListener(DeepgramTranscriptionEvents.Connect);
|
||||
ep.removeCustomEventListener(DeepgramTranscriptionEvents.ConnectFailure);
|
||||
|
||||
|
||||
};
|
||||
|
||||
const setSpeechCredentialsAtRuntime = (recognizer) => {
|
||||
if (!recognizer) return;
|
||||
if (recognizer.vendor === 'nuance') {
|
||||
const {clientId, secret} = recognizer.nuanceOptions;
|
||||
if (clientId && secret) return {client_id: clientId, secret};
|
||||
}
|
||||
else if (recognizer.vendor === 'deepgram') {
|
||||
const {apiKey} = recognizer.deepgramOptions;
|
||||
if (apiKey) return {api_key: apiKey};
|
||||
}
|
||||
else if (recognizer.vendor === 'ibm') {
|
||||
const {ttsApiKey, ttsRegion, sttApiKey, sttRegion, instanceId} = recognizer.ibmOptions;
|
||||
if (ttsApiKey || sttApiKey) return {
|
||||
tts_api_key: ttsApiKey,
|
||||
tts_region: ttsRegion,
|
||||
stt_api_key: sttApiKey,
|
||||
stt_region: sttRegion,
|
||||
instance_id: instanceId
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
normalizeTranscription,
|
||||
setChannelVarsForStt,
|
||||
removeSpeechListeners
|
||||
removeSpeechListeners,
|
||||
setSpeechCredentialsAtRuntime
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user