C
C#2y ago
eduardoA

❔ My Azure service do not Stop

I have a text to speech service, and for some reason, when I press the button to stop it dosent do anything
public class AzureTextToSpeechService {

private SpeechSynthesizer? synthesizer;

public async Task ReadOutLoudAsync(string text) {

AzureKeyCredential credentials = new(key);
TextAnalyticsClient textClient = new(endpoint, credentials);

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;
}

synthesizer = new SpeechSynthesizer(config);
IsSpeaking = true;
await synthesizer.SpeakTextAsync(text);

}

public async Task StopSpeaking() {

if (synthesizer != null && IsSpeaking == true) {
await synthesizer.StopSpeakingAsync();
]
}
}
}
public class AzureTextToSpeechService {

private SpeechSynthesizer? synthesizer;

public async Task ReadOutLoudAsync(string text) {

AzureKeyCredential credentials = new(key);
TextAnalyticsClient textClient = new(endpoint, credentials);

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;
}

synthesizer = new SpeechSynthesizer(config);
IsSpeaking = true;
await synthesizer.SpeakTextAsync(text);

}

public async Task StopSpeaking() {

if (synthesizer != null && IsSpeaking == true) {
await synthesizer.StopSpeakingAsync();
]
}
}
}
I call like this
private void StopSpeakButtonAction() {
AzureTextToSpeechService.StopSpeech();
IsPlayingEnabled = true;
IsStopEnabled = false;
}

private async void SpeakButtonction() {
await AzureTextToSpeechService.ReadOutLoudAsync(Text);
IsPlayingEnabled = false;
IsStopEnabled = true;
}
private void StopSpeakButtonAction() {
AzureTextToSpeechService.StopSpeech();
IsPlayingEnabled = true;
IsStopEnabled = false;
}

private async void SpeakButtonction() {
await AzureTextToSpeechService.ReadOutLoudAsync(Text);
IsPlayingEnabled = false;
IsStopEnabled = true;
}
9 Replies
Tvde1
Tvde12y ago
do you get any exceptions in the console? Async voids are notorious for swallowing exceptions and pretending they never happened
eduardoA
eduardoAOP2y ago
no nohing i will read bu do not stop
eduardoA
eduardoAOP2y ago
I put a breapont here but it hitts,but dosent get to the end of the methjod
eduardoA
eduardoAOP2y ago
I change it
SpeechSynthesizer speechSynthesizer;

public async Task ReadOutLoudAsync(string text) {

var key = ConstantsHelpers.AZURE_LANGUAGE_KEY;
var endpoint = new Uri(ConstantsHelpers.AZURE_LANGUAGE_URL);

AzureKeyCredential credentials = new(key);
TextAnalyticsClient textClient = new(endpoint, credentials);

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) {

var key = ConstantsHelpers.AZURE_LANGUAGE_KEY;
var endpoint = new Uri(ConstantsHelpers.AZURE_LANGUAGE_URL);

AzureKeyCredential credentials = new(key);
TextAnalyticsClient textClient = new(endpoint, credentials);

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();
}

}
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
eduardoA
eduardoAOP2y ago
? ❔ My Azure service do not Stop
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
eduardoA
eduardoAOP2y ago
it was not resolved
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity. Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server