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