文本到语音"不能从ASP.NET&QUOT听到声音;应用 [英] Cannot hear audio from ASP.NET "Text to Speech" Application
本文介绍了文本到语音"不能从ASP.NET&QUOT听到声音;应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的asp.net项目,我在下面code代表一个文本到语音功能。
在我的网页的C#文件。
in my asp.net project, I code below for a text to speech function. in my page's c# file.
byte[] SpeakText(string text)
{
using (SpeechSynthesizer s = new SpeechSynthesizer())
{
using (MemoryStream ms = new MemoryStream())
{
s.SetOutputToWaveStream(ms);
s.Speak(text);
return ms.GetBuffer();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "")
{
Response.Write(SpeakText(TextBox1.Text));
}
}
但听不到声音,同时运行。
but not hear the audio while run it.
如何解决这个问题呢?
推荐答案
尝试将响应内容类型:
Response.ContentType = "audio/wav";
因为它预计EN codeD字符也不要使用的Response.Write
。你需要写二进制以避免收到损坏的数据:
Also don't use Response.Write
as it expects encoded characters. You need to write binary to avoid getting corrupt data:
Response.Clear();
Response.ContentType = "audio/wav";
Response.BinaryWrite(SpeakText(TextBox1.Text));
Response.End();
这篇关于文本到语音"不能从ASP.NET&QUOT听到声音;应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文