我试图发表文字通用应用程序,但却陷入了困境。我看了整个互联网,找不到合适的解决方案。所以我来到这里..基本上我希望应用程序保存文本框中的所有内容为mp3。到目前为止,这是我的代码:
private void Speak_Click(object sender, RoutedEventArgs e)
{
SpeakText(Text.Text);
}
public async void SpeakText(string TTS)
{
SpeechSynthesizer ttssynthesizer = new SpeechSynthesizer();
//Set the Voice/Speaker
using (var Speaker = new SpeechSynthesizer())
{
Speaker.Voice = (SpeechSynthesizer.AllVoices.First(x => x.Gender == VoiceGender.Female));
ttssynthesizer.Voice = Speaker.Voice;
}
SpeechSynthesisStream ttsStream = await ttssynthesizer.SynthesizeTextToStreamAsync(TTS);
//play the speech
MediaElement media = new MediaElement();
media.SetSource(ttsStream, " ");
}
答案 0 :(得分:2)
我认为您可以将SpeechSynthesisStream
保存为.wav文件。然后,您可以使用MediaTranscoder
类将其重新编码为您喜欢的任何内容。
Sample Project using Media Transcoder -- use it as a refeence
将流保存到wav文件的一些额外帮助:SpeakText.xaml.cpp