我想將文本更改爲語音語音語言。 這是我的代碼:如何更改合成語音語音UWP?
private async void readText(string text)
{
var voices = SpeechSynthesizer.AllVoices;
SpeechSynthesizer speech = new SpeechSynthesizer();
speech.Voice = voices.First(x => x.Gender == VoiceGender.Female && x.Language.Contains("fr-FR"));
SpeechSynthesisStream stream = await speech.SynthesizeTextToStreamAsync(text);
mediaElement.SetSource(stream, stream.ContentType);
}
private void btnSay_Click(object sender, RoutedEventArgs e)
{
readText(txtWhat.Text);
}
但是當我嘗試運行這段代碼,有例外拋出線:
speech.Voice = voices.First(x => x.Gender == VoiceGender.Female && x.Language.Contains("fr-FR"));
「System.InvalidOperationException」類型的異常出現在系統.Linq.dll但未在用戶代碼中處理。
我該怎麼做?
嘗試FirstOrDefault。你確定安裝了法語嗎? 我已經使用 speech.Voice =(從Windows.Media.SpeechSynthesis.SpeechSynthesizer.AllVoices中的語音中獲得語音。語音。語言==「fr-FR」 選擇語音).First(); –
你有清單功能的麥克風嗎? Capabilities> –
我還沒有安裝法語,我該怎麼做? – ktos1234