I tried to use the System.Speech
class to generate speech in ASP.NET mvc application.
[HttpPost]
public ActionResult TTS(string text)
{
SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
speechSynthesizer.Speak(text);
return View();
}
But it gives the following error.
System.InvalidOperationException: 'An asynchronous operation cannot be
Started at this time. Asynchronous operations may only be started within an
asynchronous handler or module or during certain events in the Page lifecycle.
If this exception occurred while executing a Page, ensure that the Page is
marked <%@ Page Async="true" %>.
This exception may also indicate an attempt to call an "async void" method,
which is generally unsupported within ASP.NET request processing. Instead,
the asynchronous method should return a Task, and the caller should await it.
I used the System.Speech class and async methods in wpf applications.
Can the System.Speech class be used in a ASP.NET mvc application?
How to do it?
- Where should be the
<%@ Page Async="true" %>
be placed?