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