ASP. NET uses the SpeechSynthesizer class to generate voice files deployed to IIS to encounter several pits

Source: Internet
Author: User

The first step is to introduce a namespace, System.Speech.Synthesis, with the following code:

using (varnew  SpeechSynthesizer ()) {    ;   speed    speechsyn.rate =-2;   Volume     speechsyn.setoutputtodefaultaudiodevice ();    Speechsyn.setoutputtowavefile (fullfilename); // "D:\\record.wav"     speechsyn.speak (message);}

This code does not have a problem with WinForm EXE, but the exception is reported on deployment to IIS:

The asynchronous operation cannot be started now. An asynchronous operation can begin only in an asynchronous handler or module, or during a specific event in the page lifetime. If this exception occurs when the page is executed, make sure that the page is marked <%@ page async=\ "true\"%>. This exception may also indicate an attempt to invoke an "async invalid" method, which is generally not supported within ASP. Instead, the Async method should return a task, and the caller should wait for the task.

Next, the code is improved:

Try{    varTask = Task.run (() =    {        using(varSpeechsyn =NewSpeechSynthesizer ()) {Speechsyn.volume= -;//SpeedSpeechsyn.rate =-2;//VolumeSpeechsyn.setoutputtodefaultaudiodevice (); Speechsyn.setoutputtowavefile (fullfilename);//"D:\\record.wav"speechsyn.speak (message);    }    }); Task.waitall (Task);}Catch(AggregateException ae) {varSB =NewStringBuilder (); foreach(varIteminchAE. InnerExceptions) {vart =item.        GetType (); Sb. Appendline (T.namespace+"."+ T.name +" "+item.    Message); } System.IO.File.AppendAllText (Server.MapPath ("~/a.txt"), SB. ToString ());}

Found to be able to generate audio files normally, but the file is 0kb, file exception information is:

The voice is not installed on the System.InvalidOperationException system, or there is no voice available for the current security settings.

Next, troubleshoot various reasons:

1. folder permissions issues, adding various user rights is still invalid.

2. Sound card problem, but found WinForm program can generate voice files.

The 3.iis thread frees the problem because it is an asynchronous operation that keeps the current thread dormant for n seconds.

is a permissions issue:

The process identity of the application pool is changed to LocalSystem, and the voice file can be generated normally.

ASP. NET uses the SpeechSynthesizer class to generate voice files deployed to IIS to encounter several pits

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.