fix choose speech dedential by label (#441)

* fix choose speech dedential by label

* wip
This commit is contained in:
Hoan Luu Huu
2023-08-30 20:22:33 +07:00
committed by GitHub
parent a15479e6dc
commit 90df33a15c
3 changed files with 15 additions and 18 deletions

View File

@@ -719,14 +719,20 @@ class CallSession extends Emitter {
getSpeechCredentials(vendor, type, label = null) {
const {writeAlerts, AlertType} = this.srf.locals;
if (this.accountInfo.speech && this.accountInfo.speech.length > 0) {
const credential = this.accountInfo.speech.find((s) => s.vendor === vendor &&
((label && s.label === label) || label === null));
// firstly check if account level has expected credential
let credential = this.accountInfo.speech.find((s) => s.vendor === vendor &&
s.label === label && s.account_sid);
if (!credential) {
// check if SP level has expected credential
credential = this.accountInfo.speech.find((s) => s.vendor === vendor &&
s.label === label && !s.account_sid);
}
if (credential && (
(type === 'tts' && credential.use_for_tts) ||
(type === 'stt' && credential.use_for_stt)
)) {
this.logger.info(`Speech credential vendor: ${credential.vendor}
${credential.label ? `, label: ${credential.label}` : ''} is chosen`);
${credential.label ? `, label: ${credential.label}` : ''} is chosen`);
if ('google' === vendor) {
if (type === 'tts' && !credential.tts_tested_ok ||
type === 'stt' && !credential.stt_tested_ok) {