diff --git a/lib/utils/transcription-utils.js b/lib/utils/transcription-utils.js index 91fc1701..4d2db00d 100644 --- a/lib/utils/transcription-utils.js +++ b/lib/utils/transcription-utils.js @@ -822,9 +822,22 @@ module.exports = (logger) => { if ('google' === vendor) { const useV2 = rOpts.googleOptions?.serviceVersion === 'v2'; + const {parentPath} = rOpts.googleOptions || {}; const version = useV2 ? 'v2' : 'v1'; let {model} = rOpts; model = model || selectDefaultGoogleModel(task, language, version); + + /** + * For STT v2, Google routes regional resources only via regional endpoints. + * A parentPath ending in `/locations/` (anything other than `global`) + * requires the request to go to `-speech.googleapis.com` instead of + * the default `speech.googleapis.com`. + */ + let derivedSttUri; + if (useV2 && parentPath) { + const m = parentPath.match(/\/locations\/([^/]+)/); + if (m && m[1] && m[1] !== 'global') derivedSttUri = `${m[1]}-speech.googleapis.com`; + } opts = { ...opts, ...(sttCredentials && {GOOGLE_APPLICATION_CREDENTIALS: JSON.stringify(sttCredentials.credentials)}), @@ -858,8 +871,10 @@ module.exports = (logger) => { ...(rOpts.naicsCode > 0 && {GOOGLE_SPEECH_METADATA_INDUSTRY_NAICS_CODE: rOpts.naicsCode}), GOOGLE_SPEECH_METADATA_RECORDING_DEVICE_TYPE: 'phone_line', ...(useV2 && { - GOOGLE_SPEECH_RECOGNIZER_PARENT: `projects/${sttCredentials.credentials.project_id}/locations/global`, + GOOGLE_SPEECH_RECOGNIZER_PARENT: parentPath || + `projects/${sttCredentials.credentials.project_id}/locations/global`, GOOGLE_SPEECH_CLOUD_SERVICES_VERSION: 'v2', + ...(derivedSttUri && {GOOGLE_SPEECH_TO_TEXT_URI: derivedSttUri}), ...(rOpts.googleOptions?.speechStartTimeoutMs && { GOOGLE_SPEECH_START_TIMEOUT_MS: rOpts.googleOptions.speechStartTimeoutMs }), diff --git a/package-lock.json b/package-lock.json index 0d686012..f0f897db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "@jambonz/speech-utils": "^0.2.30", "@jambonz/stats-collector": "^0.1.10", "@jambonz/time-series": "^0.2.17", - "@jambonz/verb-specifications": "^0.1.11", + "@jambonz/verb-specifications": "^0.1.12", "@modelcontextprotocol/sdk": "^1.9.0", "@opentelemetry/api": "^1.8.0", "@opentelemetry/exporter-jaeger": "^1.23.0", @@ -1647,9 +1647,9 @@ } }, "node_modules/@jambonz/verb-specifications": { - "version": "0.1.11", - "resolved": "https://registry.npmjs.org/@jambonz/verb-specifications/-/verb-specifications-0.1.11.tgz", - "integrity": "sha512-2YWqBXhLUD+WLipMdysE155eOSgFVW3id0l4Ci37OYELJIG+GeJYMubReSlMXthU/WoVk91ATu+XkSsjuVO1dg==", + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/@jambonz/verb-specifications/-/verb-specifications-0.1.12.tgz", + "integrity": "sha512-Ddqk78om3k2l1Kj6IGB945W8KOOEwKPLxWeXao6H4jMCbrRponCN+gFOOFUC8q4KRmoe4yaQ6Y02UkejPtaYzQ==", "license": "MIT", "dependencies": { "debug": "^4.3.4", diff --git a/package.json b/package.json index 54b0b971..b2b4325d 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@jambonz/speech-utils": "^0.2.30", "@jambonz/stats-collector": "^0.1.10", "@jambonz/time-series": "^0.2.17", - "@jambonz/verb-specifications": "^0.1.11", + "@jambonz/verb-specifications": "^0.1.12", "@modelcontextprotocol/sdk": "^1.9.0", "@opentelemetry/api": "^1.8.0", "@opentelemetry/exporter-jaeger": "^1.23.0",