我在一个ASP.NET应用程序中有以下代码片段(非Silverlight)
string sText = "Test text";
SpeechSynthesizer ss = new SpeechSynthesizer();
MemoryStream ms = new MemoryStream();
ss.SetOutputToWaveStream(ms);
ss.Speak(sText);
//Need to send the ms Memory stream to the user for listening/downloadin我如何:
。
有人能帮忙完成代码吗?
编辑:非常感谢任何帮助.
发布于 2009-11-12 04:23:36
这里是IHttpHandler的主要部分,它可以实现您想要的功能。将处理程序URL插入play标记或将其输送到任何要在浏览器中播放的内容,并添加查询字符串检查"downloadFile“var或其他内容,以便有条件地添加内容处理:附件;filename=whatever.wav标题(如果您想下载)。没有必要使用中间文件(尽管如果不运行在另一个线程上,SetOutputToWaveStream就会失败)。
public void ProcessRequest(HttpContext context)
{
MemoryStream ms = new MemoryStream();
context.Response.ContentType = "application/wav";
Thread t = new Thread(() =>
{
SpeechSynthesizer ss = new SpeechSynthesizer();
ss.SetOutputToWaveStream(ms);
ss.Speak("hi mom");
});
t.Start();
t.Join();
ms.Position = 0;
ms.WriteTo(context.Response.OutputStream);
context.Response.End();
}https://stackoverflow.com/questions/1719780
复制相似问题