C
C#17mo ago
eduardoA

❔ Azure Speech Service wont shut up

I am using azure in a WPF app, where I have two buttons, Read, and Stop The problem is, that when I click on Stop, it dosent do anything. I already tried to wrap the entire speak process into a thread and cancelling it, and it works 3 times and that it
private async Task StopSpeakButtonAction() {
await AzureTextToSpeech.StopSpeechAsync();
IsPlayingEnabled = true;
IsStopEnabled = false;
}

private async Task SpeakButtonction() {
await AzureTextToSpeech.ReadOutLoudAsync(Text!);
IsPlayingEnabled = false;
IsStopEnabled = true;
}
private async Task StopSpeakButtonAction() {
await AzureTextToSpeech.StopSpeechAsync();
IsPlayingEnabled = true;
IsStopEnabled = false;
}

private async Task SpeakButtonction() {
await AzureTextToSpeech.ReadOutLoudAsync(Text!);
IsPlayingEnabled = false;
IsStopEnabled = true;
}
SpeechSynthesizer speechSynthesizer;

public async Task ReadOutLoudAsync(string text) {


Response<DetectedLanguage> response = textClient.DetectLanguage(text);

DetectedLanguage lang = response.Value;

var config = SpeechConfig.FromSubscription(
ConstantsHelpers.AZURE_SPEECH_KEY,
ConstantsHelpers.AZURE_SPEECH_REGION);


switch (lang.Iso6391Name) {
case "en":
config.SpeechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (en-US, SaraNeural)";
config.SpeechSynthesisLanguage = "en-us";
break;
case "es":
config.SpeechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (es-VE, PaolaNeural)";
config.SpeechSynthesisLanguage = "es-VE";
break;
default:
break;
}



speechSynthesizer = new SpeechSynthesizer(config);
await speechSynthesizer.StartSpeakingTextAsync(text);

}


public async Task StopSpeechAsync() {
await speechSynthesizer.StopSpeakingAsync();
}
SpeechSynthesizer speechSynthesizer;

public async Task ReadOutLoudAsync(string text) {


Response<DetectedLanguage> response = textClient.DetectLanguage(text);

DetectedLanguage lang = response.Value;

var config = SpeechConfig.FromSubscription(
ConstantsHelpers.AZURE_SPEECH_KEY,
ConstantsHelpers.AZURE_SPEECH_REGION);


switch (lang.Iso6391Name) {
case "en":
config.SpeechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (en-US, SaraNeural)";
config.SpeechSynthesisLanguage = "en-us";
break;
case "es":
config.SpeechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (es-VE, PaolaNeural)";
config.SpeechSynthesisLanguage = "es-VE";
break;
default:
break;
}



speechSynthesizer = new SpeechSynthesizer(config);
await speechSynthesizer.StartSpeakingTextAsync(text);

}


public async Task StopSpeechAsync() {
await speechSynthesizer.StopSpeakingAsync();
}
1 Reply
Accord
Accord17mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.