mirror of
https://github.com/jambonz/speech-utils.git
synced 2026-07-23 04:31:47 +00:00
support self hosted microsoft
This commit is contained in:
+12
-3
@@ -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
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user