This commit is contained in:
Zeeshaun
2026-04-22 15:13:45 -05:00
parent ce7775dc43
commit 0f2cccbc30
7 changed files with 43 additions and 154 deletions
View File
@@ -214,20 +214,12 @@
return;
}
try
{
await JSRuntime.InvokeVoidAsync(
"synthesizeSpeech",
spitConfiguration.SpeechApiKey,
spitConfiguration.Region,
spitConfiguration.SpeechEndpoint,
_textToSpeech.Ssml);
}
catch (JSException ex)
{
Log.Error(ex, "Play sound failed.");
toastService.ShowError($"Unable to play sound. {ex.Message}");
}
await JSRuntime.InvokeVoidAsync(
"synthesizeSpeech",
spitConfiguration.SpeechApiKey,
spitConfiguration.Region,
spitConfiguration.SpeechEndpoint,
_textToSpeech.Ssml);
}
public void OpenDirectory(string fileDestination)
@@ -48,7 +48,7 @@ System.Text.RegularExpressions.Regex.IsMatch(userAgent, @"MSIE \d|Trident.*rv:")
<script src="_framework/blazor.server.js"></script>
<script src="_content/Blazored.Typeahead/blazored-typeahead.js"></script>
<script src="js/microsoft.cognitiveservices.speech.sdk.bundle.js" asp-append-version="true"></script>
<script src="js/SpeechFunctions.js" asp-append-version="true"></script>
<script src="js/microsoft.cognitiveservices.speech.sdk.bundle.js"></script>
<script src="js/SpeechFunctions.js"></script>
</body>
</html>
@@ -4,15 +4,15 @@
"AppName": "Speech Production Interface Tool",
"SeqApiKey": "VALUE-IN-KEYVAULT",
"SeqUrl": "https://qa-seq.lcu-internal.com",
"SpeechApiKey": "VALUE-IN-KEYVAULT",
"SpeechEndpoint": "VALUE-IN-KEYVAULT",
"SpeechApiKey": "ce503e1ea0d94720b4a1f6b66007a2ea",
"SpeechEndpoint": "https://speech-qa-uscz.cognitiveservices.azure.com",
"FetchTokenUri": "/sts/v1.0/issueToken",
"VoicesUrl": "/cognitiveservices/voices/list",
"VoicesUrl": "/tts/cognitiveservices/voices/list",
"OcpApimSubscriptionKey": "Ocp-Apim-Subscription-Key",
"Region": "eastus",
"FileDestination": "\\\\zeus\\DataIntegrationsQA\\Spit\\Test\\",
"FileExtention": ".wav",
"SpitRoles": "IT Development",
"SpitRoles": "SpitUser - QA",
"DefaultLanguageWithCountryCode": "en-US",
"EnabledLanguageOptionCodes": [ "en", "es" ]
},
@@ -22,8 +22,8 @@
},
"AzureAd": {
"TenantId": "63cd1554-2783-4a86-ae50-b9e6c21c9499",
"ClientId": "VALUE-IN-KEYVAULT",
"ClientSecret": "VALUE-IN-KEYVAULT",
"ClientId": "b756f2d1-8f23-4bbe-b183-c98f6931091c",
"ClientSecret": "HnS8Q~uHMa-hGMEn6tzpTml1AtNow9G.SVBTZaiW",
"Instance": "https://login.microsoftonline.com/",
"Domain": "landmarkcu.onmicrosoft.com",
"CallbackPath": "/signin-oidc",
@@ -31,8 +31,8 @@
},
"Security": {
"AccessPolicies": {
"IT Development": {
"Groups": "IT Development"
"SpitUser - QA": {
"Groups": "SpitUser - QA"
}
}
}
@@ -1,129 +1,26 @@
function synthesizeSpeech(subscriptionKey, region, endpoint, ssml) {
return new Promise(function (resolve, reject) {
const SpeechSDK = window.SpeechSDK;
var SpeechSDK;
if (!!window.SpeechSDK) {
SpeechSDK = window.SpeechSDK;
}
if (!SpeechSDK) {
reject(new Error("Speech SDK is not loaded."));
return;
}
const speechConfig = endpoint
? SpeechSDK.SpeechConfig.fromEndpoint(new URL(endpoint), subscriptionKey)
: SpeechSDK.SpeechConfig.fromSubscription(subscriptionKey, region);
const audioConfig = SpeechSDK.AudioConfig.fromDefaultSpeakerOutput();
let synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig, audioConfig);
let speechConfig;
synthesizer.speakSsmlAsync(
ssml,
function (result) {
window.console.log(result);
synthesizer.close();
synthesizer = undefined;
},
function (err) {
window.console.log(err);
try {
speechConfig = createSpeechConfig(SpeechSDK, subscriptionKey, region, endpoint);
} catch (error) {
reject(error);
return;
}
const audioConfig = SpeechSDK.AudioConfig.fromDefaultSpeakerOutput();
let synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig, audioConfig);
synthesizer.speakSsmlAsync(
ssml,
function (result) {
try {
if (result.reason !== SpeechSDK.ResultReason.SynthesizingAudioCompleted) {
reject(new Error(buildSynthesisErrorMessage(SpeechSDK, result, region, endpoint)));
return;
}
resolve();
} finally {
synthesizer.close();
synthesizer = undefined;
}
},
function (error) {
try {
reject(new Error(normalizeSpeechError(error, region, endpoint)));
} finally {
synthesizer.close();
synthesizer = undefined;
}
});
});
}
function createSpeechConfig(SpeechSDK, subscriptionKey, region, endpoint) {
const trimmedEndpoint = typeof endpoint === "string" ? endpoint.trim() : "";
const trimmedRegion = typeof region === "string" ? region.trim() : "";
if (trimmedRegion) {
if (!trimmedEndpoint) {
return SpeechSDK.SpeechConfig.fromSubscription(subscriptionKey, trimmedRegion);
}
}
if (trimmedEndpoint) {
const endpointUrl = new URL(trimmedEndpoint);
const hasCustomPath = endpointUrl.pathname && endpointUrl.pathname !== "/";
if (hasCustomPath) {
return SpeechSDK.SpeechConfig.fromEndpoint(endpointUrl, subscriptionKey);
}
return SpeechSDK.SpeechConfig.fromHost(endpointUrl, subscriptionKey);
}
if (trimmedRegion) {
return SpeechSDK.SpeechConfig.fromSubscription(subscriptionKey, trimmedRegion);
}
throw new Error("Speech configuration is missing both endpoint and region.");
}
function buildSynthesisErrorMessage(SpeechSDK, result, region, endpoint) {
const cancellation = SpeechSDK.CancellationDetails.fromResult(result);
const parts = [
"Speech synthesis failed.",
"Reason: " + result.reason
];
if (cancellation) {
if (cancellation.reason !== undefined) {
parts.push("CancellationReason: " + cancellation.reason);
}
if (cancellation.errorCode !== undefined) {
parts.push("CancellationErrorCode: " + cancellation.errorCode);
}
if (cancellation.errorDetails) {
parts.push("ErrorDetails: " + cancellation.errorDetails);
}
}
appendConnectionDetails(parts, region, endpoint);
return parts.join(" ");
}
function normalizeSpeechError(error, region, endpoint) {
const parts = ["Speech synthesis connection failed."];
if (error instanceof Error && error.message) {
parts.push(error.message);
} else if (typeof error === "string" && error.trim()) {
parts.push(error.trim());
} else if (error && error.toString) {
parts.push(error.toString());
} else {
parts.push("No error details were provided.");
}
appendConnectionDetails(parts, region, endpoint);
return parts.join(" ");
}
function appendConnectionDetails(parts, region, endpoint) {
const trimmedRegion = typeof region === "string" ? region.trim() : "";
const trimmedEndpoint = typeof endpoint === "string" ? endpoint.trim() : "";
if (trimmedRegion) {
parts.push("Region: " + trimmedRegion);
}
if (trimmedEndpoint) {
parts.push("Endpoint: " + trimmedEndpoint);
}
synthesizer.close();
synthesizer = undefined;
});
}
@@ -2,15 +2,15 @@
"Primary": {
"FileDestination": "\\\\zeus\\DataIntegrationsQA\\Spit\\",
"SeqUrl": "https://qa-seq.lcu-internal.com",
"SpitRoles": "IT Development"
"SpitRoles": "SpitUser - QA"
},
"FileOperationsConfiguration": {
"Url": "https://qa-fileoperationsapi.lcu-internal.com"
},
"Security": {
"AccessPolicies": {
"IT Development": {
"Groups": "IT Development"
"SpitUser - QA": {
"Groups": "SpitUser - QA"
}
}
}
@@ -2,15 +2,15 @@
"Primary": {
"FileDestination": "\\\\zeus\\DataIntegrationsUAT\\Spit\\",
"SeqUrl": "https://uat-seq.lcu-internal.com",
"SpitRoles": "IT Development"
"SpitRoles": "SpitUser - QA"
},
"FileOperationsConfiguration": {
"Url": "https://uat-fileoperationsapi.lcu-internal.com"
},
"Security": {
"AccessPolicies": {
"IT Development": {
"Groups": "IT Development"
"SpitUser - QA": {
"Groups": "SpitUser - QA"
}
}
}