我有一个将文本文件读入字节数组的应用程序,然后将这个数组转换为string,并将其作为输入发送到SpeechSynthesizer的the方法,但是the方法不会说话。
如果我只发送一个普通的临时字符串,它就能正常工作。但是,当我将字节数组转换为string时,它不起作用。
我所做的是,当我从文本文件中读取这一行时,我使用了这一行代码。
UTF8Encoding temp = new UTF8Encoding(true);
string whatToSay = temp.getString(b);
speech.Speak(whatToSay); // it doesn't work even though the above line returns the
correct string所以我想知道如果我只写这样的话有什么区别:
spech.Speak("hello"); // this works perfect这些字符串之间有什么区别吗?说话的方法没有得到UTF8?
发布于 2013-12-06 14:31:28
我看不出您的代码有什么问题,但是您的变量b可能不一样。我不知道出了什么问题,但您也可以尝试将音频文件保存在某个地方,并检查它是否正在播放:
using (SpeechSynthesizer synth = new SpeechSynthesizer()) {
synth.SetOutputToWaveFile(@"C:\temp\Sample.wav");
PromptBuilder builder = new PromptBuilder();
builder.AppendText("Hello World !"); //You can send a variable here also.
synth.Speak(builder);
}https://stackoverflow.com/questions/20426189
复制相似问题