Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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:
 
Share this answer
 
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.
 
Share this answer
 
Well you could always try the Speak()[^] method rather than SpeakAsync().
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900