简体   繁体   English

C#语音合成

[英]C# Speech Synthesis

I have an application that reads a text file into byte array, then I convert this array to string and send it as an input to the speak method of the SpeechSynthesizer but the SPEAK method doen't speak.. 我有一个应用程序将文本文件读入字节数组,然后我将此数组转换为字符串并将其作为输入发送到SpeechSynthesizer的speak方法,但SPEAK方法不说话..

if I just send a regular temp string it works fine.. but when I convert the byte array to string it doesn't work. 如果我只是发送一个常规的临时字符串它工作正常..但是当我将字节数组转换为字符串时,它不起作用。

what I did is when I read the line from the text file I use this lines of code 我做的是当我从文本文件中读取行时,我使用这行代码

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

so I wonder what is the difference if I write just this: 所以我想知道如果我写这个有什么区别:

spech.Speak("hello"); // this works perfect

is there any difference between those strings? 这些字符串之间有什么区别吗? the speak method doesn't get UTF8 ? speak方法没有获得UTF8?

I couldn't see any problem with your code but maybe your variable b is something different. 我看不到你的代码有任何问题,但也许你的变量b是不同的。 I am not sure what is wrong but you can also try saving the audio file somewhere and checking it if it is playing something or not: 我不确定有什么问题,但您也可以尝试将音频文件保存到某处并检查它是否正在播放:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM