简体   繁体   English

使用SpeechLib托管问题

[英]Hosting Problems using SpeechLib

Hi I'm developing a web project with c# and using VS2010. 嗨,我正在用c#开发一个Web项目并使用VS2010。 I'm using the SpeechLib, that converts text to speech. 我正在使用SpeechLib,它将文本转换为语音。 Locally in my computer all works well, but when hosting the web page the page doesn't works and the error 500 is outputted. 在我的本地计算机上,一切正常,但是在托管网页时,该页面无法正常工作,并输出错误500。

As stated in another old post ( link ), the problem seems to be that this library tries to write a temporary file in a folder without the necessary permissions. 如另一篇旧文章( link )所述,问题似乎在于该库试图在没有必要权限的情况下将临时文件写入文件夹。 The problem but was not solved. 问题,但没有解决。

How can I solve this problem? 我怎么解决这个问题? Thanks! 谢谢!

One way to get around disk permission issue is to not save the audio to disk. 解决磁盘权限问题的一种方法是不将音频保存到磁盘。 To do this, you would convert the output to a stream object, which can be returned via a web page, HTTP handler, or MVC action. 为此,您需要将输出转换为流对象,可以通过网页,HTTP处理程序或MVC操作返回该对象。 Unfortunately, the "SetOutputToAudioStream" only returns raw PCM audio. 不幸的是,“ SetOutputToAudioStream”仅返回原始PCM音频。

In order to output other encodings like µ-law (mu-law, u-law, ulaw), you have to gain access to a non-public SetOutputStream method by using reflection. 为了输出诸如µ-law(mu-law,u-law,ulaw)之类的其他编码,您必须使用反射来访问非公共SetOutputStream方法。 Below is a code snippet that accomplishes this and returns a byte array: 下面是完成此操作并返回字节数组的代码段:

using System.Reflection;

/* Beginning Code */

byte outputWavBytes;

MemoryStream outputWav = new MemoryStream()
using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
    var mi = synth.GetType().GetMethod("SetOutputStream", BindingFlags.Instance | BindingFlags.NonPublic);
    var fmt = new SpeechAudioFormatInfo(EncodingFormat.ULaw, 8000, 8, 1, 20, 2, null)
    mi.Invoke(synth, new object[] { outputWav, fmt, true, true });
    synth.Speak("This is a test to stream a different encoding.");
    outputWav.Seek(0, SeekOrigin.Begin);
    outputWavBytes = outputWav.GetBuffer();
}



/* End Code */

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

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