创建一个将文本转换为语音的ASP.NET应用程序 [英] Creating a ASP.NET application converting text to speech

查看:115
本文介绍了创建一个将文本转换为语音的ASP.NET应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建将ASP.NET中的文本转换为语音的应用程序中寻求一些见识。从我的初步研究看来,


  1. MS SAPI要求客户端下载ActiveX组件并可以支持大量的要转换的文本。我们的客户不愿意在他们的系统上安装任何组件,因此这种方法可能成功也可能不会成功。


  2. 我确实对.NET 3.0有所了解, System.Speech.Synthesis命名空间。转换是否在服务器上进行?如果是这样,我将如何为客户服务?


我们的要求是能够转换大量文本,应该具有可扩展性和可靠性。哪种技术是生产就绪的技术,能够在较短的时间间隔内满足大量请求。



任何想法都值得赞赏。

解决方案

默认情况下,ASP.Net应用程序的运行权限不足,无法访问语音合成,并且尝试运行Larsenal的代码将因安全错误而失败。 p>

通过在服务器上运行单独的WCF服务(作为常规Windows服务),我能够在应用程序中解决此问题。然后,ASP.Net应用程序与该服务进行通信。该服务只是包装了拉森纳尔的代码,返回给定文本字符串的字节数组。



还有一兆字节的文本吗?那是一本大书。



编辑,09年11月12日,回答了一些评论:



System.Speech可以返回字节数组,也可以保存到wav文件,然后可以将其馈送到嵌入在用户页面上的媒体播放器。当我建立会说话的网页时,它的工作方式如下:



1)Page.aspx包含一个嵌入标签,该标签将Windows Media Player放置在页面上。源是 PlayText.aspx?Textid = whatever。

2)PlayText.aspx加载适当的文本,并(通过WCF)与语音阅读器服务通信,将其传递给阅读的文本。 >
3)Speechreader服务创建一个MemoryStream并调用SpeechSynthesiser.SetOutputToWaveStream,然后将流作为单个字节数组返回。此数组是到客户端的Response.Write()-ed。



这是SpeechReader服务的实质:

  byte [] ITextReader.SpeakText(字符串文本)
{
使用(SpeechSynthesizer s = new SpeechSynthesizer())
{
使用(MemoryStream ms = new MemoryStream())
{
s.SetOutputToWaveStream(ms);
s.Speak(text);
返回ms.GetBuffer();
}
}
}

我很确定在后端,这将返回巨大的XML字节数组,并且效率极低。我只是将其用作概念证明,因此并未对此进行研究。如果您打算在生产中使用它,请确保它在内部不返回这样的内容:

 < byte> 23< / byte> 
< byte> 42< / byte>
< byte> 117< / byte>
...


I seek some insight in creating an application that converts text to speech in ASP.NET. From my initial research, it appears that:

  1. MS SAPI requires the client to download an ActiveX component and can support large amounts of text to be converted. Our clients are not willing to install any components on their systems, so this approach may or may not fly.

  2. I do understand with .NET 3.0, we have the System.Speech.Synthesis namespace. Does the conversion take place on the server? If so, how would I serve it to the client?

Our requirements are ability to convert large amount of text, should be scalable and reliable. Which technology is "production ready" capable of serving a large number of requests in a short time interval.

Any thoughts are appreciated.

解决方案

By default, ASP.Net applications don't run with sufficient permissions to access Speech Synthesis, and attempting to run Larsenal's code will fail with a security error.

I was able to get around this in an app by having a separate WCF service running on the server, as a regular Windows Service. The ASP.Net application then communicated with that service. That service just wrapped Larsenal's code, returning an array of bytes, given a string of text.

Also, one megabyte of text? That's a good-sized novel.

Edit, 11-12-09, answering some comments:

System.Speech can either return an array of bytes, or save to a wav file, which you can then feed to a media player embedded on the user's page. When I built my talking web page, it worked like this:

1) Page.aspx includes an 'embed' tag that puts a Windows Media Player on the page. The source is "PlayText.aspx?Textid=whatever".
2) PlayText.aspx loads the appropriate text, and communicates (via WCF) to the speechreader service, handing it the text to read.
3) The Speechreader service creates a MemoryStream and calls SpeechSynthesiser.SetOutputToWaveStream, and then returns the stream as a single array of bytes. This array is Response.Write()-ed to the client.

Here's the meat of the SpeechReader service:

    byte[] ITextReader.SpeakText(string text)
    {
        using (SpeechSynthesizer s = new SpeechSynthesizer())
        {
            using (MemoryStream ms = new MemoryStream())
            {
                s.SetOutputToWaveStream(ms);
                s.Speak(text);
                return ms.GetBuffer();
            }
        }
    }

I'm pretty sure that on the back end, this returns an enormous XML array-of-bytes, and is horribly inefficient. I just did it as a proof of concept, and so didn't research that. If you intend to use this in production, make sure that it's not internally returning something like this:

<byte>23</byte>
<byte>42</byte>
<byte>117</byte>
...

这篇关于创建一个将文本转换为语音的ASP.NET应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆