support self hosted microsoft

This commit is contained in:
Quan HL
2023-08-09 17:56:38 +07:00
parent d07344ba3b
commit 7a91876cd7
2 changed files with 19 additions and 4 deletions
+12 -3
View File
@@ -14,7 +14,7 @@ const {
CancellationDetails,
SpeechSynthesisOutputFormat
} = sdk;
const {makeSynthKey, createNuanceClient, createKryptonClient, createRivaClient, noopLogger} = require('./utils');
const {makeSynthKey, createNuanceClient, createKryptonClient, createRivaClient, noopLogger, isValidHttpOrWsUrl} = require('./utils');
const getNuanceAccessToken = require('./get-nuance-access-token');
const {
SynthesisRequest,
@@ -309,10 +309,19 @@ const synthMicrosoft = async(logger, {
const {api_key: apiKey, region, use_custom_tts, custom_tts_endpoint} = credentials;
const trimSilence = filePath.endsWith('.r8');
let content = text;
const speechConfig = SpeechConfig.fromSubscription(apiKey, region);
let speechConfig;
if (use_custom_tts && isValidHttpOrWsUrl(custom_tts_endpoint)) {
if (apiKey) {
speechConfig = SpeechConfig.fromEndpoint(custom_tts_endpoint, apiKey);
} else {
speechConfig = SpeechConfig.fromEndpoint(custom_tts_endpoint);
}
} else {
speechConfig = SpeechConfig.fromSubscription(apiKey, region);
}
speechConfig.speechSynthesisLanguage = language;
speechConfig.speechSynthesisVoiceName = voice;
if (use_custom_tts && custom_tts_endpoint) {
if (use_custom_tts && !isValidHttpOrWsUrl(custom_tts_endpoint)) {
speechConfig.endpointId = custom_tts_endpoint;
/**
+7 -1
View File
@@ -106,6 +106,11 @@ const createRivaClient = async(rivaUri) => {
return client;
};
const isValidHttpOrWsUrl = (url) => {
const pattern = new RegExp('^(https?:\/\/|wss?:\/\/)');
return !!url.match(pattern);
}
module.exports = {
makeSynthKey,
@@ -117,5 +122,6 @@ module.exports = {
createRivaClient,
makeBasicAuthHeader,
NUANCE_AUTH_ENDPOINT,
noopLogger
noopLogger,
isValidHttpOrWsUrl
};