private static SpeechSynthesizer synth;
public async static Task<SpeechSynthesizer> SpeechSynth(string dataToSpeak)
{
synth = new SpeechSynthesizer();
IEnumerable<VoiceInformation> englishVoices = from voice in InstalledVoices.All
where voice.Language == "en-US"
&& voice.Gender.Equals(VoiceGender.Female)
select voice;
if (englishVoices.Count() > 0)
{
synth.SetVoice(englishVoices.ElementAt(0));
}
await synth.SpeakTextAsync(dataToSpeak);
return synth;
}
public static void CancelSpeech()
{
synth.CancelAll();
}
現在所說的SpeechSynth("Some Data to Speak")
,你想要的,只要你想取消的話,只需要調用CancelSpeech()
。
它完成了!請享用...!
@會,它的工作!下次更仔細地閱讀文件。你能寫一個答案,所以我可以將其標記爲答案?謝謝! – Jim
完成。如果你編輯並添加一小段代碼給我的答案,那就證明我不會哭泣。 – Will