异步语音合成器 [英] An Async SpeechSynthesizer

查看:63
本文介绍了异步语音合成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

(无论如何,这听起来像是一个魔兽世界NPC)

我一直在努力尝试要尝试的家庭项目.

我想在网页中使用System.Speech.Synthesis,但它给了我以下错误.

在这种情况下,不允许异步操作.页面启动异步操作必须将Async属性设置为true,并且异步操作只能在PreRenderComplete事件之前的页面上启动.

老实说,我不知道该怎么办,这就是我所要做的

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Speech.Synthesis;

公共局部类_Default:System.Web.UI.Page
{
受保护的void Page_Load(对象发送者,EventArgs e)
{

}
受保护的void Button1_Click(对象发送者,EventArgs e)
{

SpeechSynthesizer语音=新的SpeechSynthesizer();
speech.SpeakAsync(TextBox1.Text);

}
}

单击该按钮时,它应该读取文本框中的内容.
对于Windows应用程序,我已经做过多次,但是对于Web应用程序,我从未做过.

有人对我有建议吗?

欢迎任何建议.

谢谢,

Harry Neethling

Hi there,

(That sounded like a world of warcraft NPC, anyway)

I have been struggling a bit with a home project that I am trying to figure out.

I want to use System.Speech.Synthesis in a web page but it gives me the following error.

Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event.

To be honest I have no idea what to do, here is what I have

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Speech.Synthesis;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{

SpeechSynthesizer speech = new SpeechSynthesizer();
speech.SpeakAsync(TextBox1.Text);

}
}

When the button is clicked, it should read what ever is in the textbox.
I have done this multiple times for windows applications, but never before for a web application.

Does anyone have a suggestion for me?

Any advice is welcome.

Thanks,

Harry Neethling

推荐答案

这在Web环境中不起作用.

为此,您需要创建语音文件并将其下载到客户端...:laugh:

基本上,在请求/响应体系结构中(就像Web一样),您只能向浏览器中写入内容,而没有太多内容.
:sigh:
This will not work in Web environment.

To make this happen, you need to create the speech file and download that to the client... :laugh:

Basically in Request/ Response architecture(as web is) you can only write something to the browser and nothing much.
:sigh:


只是要澄清一点-您的问题是,在测试中,服务器和客户端是相同的,如果您可以正常使用并将其部署为站点,则在服务器上运行的C#代码将导致服务器而不是客户端计算机讲话.理解这很重要,您在C#或VB.NET中所做的任何事情都在服务器上运行,并且应该仅存在于为了驱动客户端可以在IE中体验到的HTML/CSS/javascript而要做的事情.
Just to clarify a little - your issue is that while in testing, the server and client are the same, if you got this to work and deployed it as a site, the C# code, running on the server, would cause the server to speak, and not the client machine. This is imporant to understand, anything you do in C# or VB.NET runs on the server and should only exist to work out what to do in order to drive the HTML/CSS/javascript that is all that the client can experience in IE.


好吧,您可以随时尝试 Speak() [
Well you could always try the Speak()[^] method rather than SpeakAsync().


这篇关于异步语音合成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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