使用通用处理程序 ASHX

问题描述

我正在使用来自 VOICERSS 的 Text-To-Speech-API,我从 Javascript 中调用它并获取音频。免费版限制为每天 300 次 HttpRequest。

我像这样使用 API:

var testAudio = new Audio();
        testAudio.src = "http://api.voiceRSS.org/?key=********&hl=de-de&src=" + text;
        testAudio.volume = 1;
        testAudio.play();

现在我正在尝试使用 Interop.Speechlib.DLL 自行构建它。我不知道 URL 后面是什么,但我认为它必须类似于 Generic Handler,它流式传输音频文件。当我在浏览器中调用 URL 时,我只听到 Speech-Synthesis-Sound。

现在我正在尝试使用通用处理程序来实现这一点,但它自动向我显示音频播放器,但不播放声音。

我的 ASHX 代码

string text = context.Request.QueryString["text"];
        if(text != null)
        {
            SpVoice speech = new SpVoice();
            SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
            //SpMemoryStream SpMemoryStream = new SpMemoryStream();
            SpFileStream SpFileStream = new SpFileStream();
            string pfad = context.Server.MapPath("/temp/");
            string filename = "temp" + DateTime.Now.ToString();
            filename = filename.Replace(" ","");
            filename = filename.Replace(".","");
            filename = filename.Replace(":","");
            filename = pfad + filename + ".wav";
            SpFileStream.Open(filename,SpFileMode,false);
            speech.AudioOutputStream = SpFileStream;
            //speech.AudioOutputStream = SpMemoryStream;
            speech.Volume = 100;
            speech.Speak(text,SpeechVoiceSpeakFlags.SVSFlagsAsync);
            SpFileStream.Close();
            context.Response.Clear();
            context.Response.BinaryWrite(File.ReadAllBytes(filename));
        }

有人能指出我正确的方向吗,我可以在 JS 中将音频源指向一个进行文本到语音合成的 URL,好吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)