Recently in the development of a queuing system, where the server (management side) needs to have a call function, that is, the point button to broadcast "XXX customer please sit" voice.
After a search on the Internet, the Web-based voice playback scheme for the specified text has these kinds of
1 Free online Services, some websites provide text-to-speech file function, which is like Baidu, Iflytek also provide interface calls, but for me, need to network this condition is rejected.
2 using the Microsoft built-in Activatex voice control, the simplest but also obvious shortcomings, can only be used in IE, considering that the system may be used on the tablet, so this program is also rejected.
JS Code
var voiceobj = new ActiveXObject ("Sapi.spvoice");
Voiceobj.speak ("XXX customer please be seated", 1);
3 The emphasis came. The front-end uses the H5 audio playback component, and the background uses SpeechSynthesizer to generate the WAV stream file streams directly to the player's SRC output.
The approximate code is as follows:
Front-end HTML
<id= "Audioplay"><type= "audio/ WAV "/></audio>...function play (calltext) {var Audioplay = document.getElementById ("Audioplay"); audioplay.src = ". /voicehandler.ashx? Voice= "+ Calltext;audioplay.play ();}
C # background code
Public classVoicehandler:ihttphandler { Public voidProcessRequest (HttpContext context) {Thread T=NULL; Context. Response.ContentType="Application/wav"; using(MemoryStream ms =NewMemoryStream ()) {T=NewThread (() ={SpeechSynthesizer ss=NewSpeechSynthesizer (); Try{ss. Rate= -5; Ss. Volume= -; Ss. Setoutputtowavestream (MS); Ss. Speak (context. request["Voice"]); } Catch(Exception ex) {ss. Dispose (); Context. Response.Write (ex. Message); } }); T.start (); T.join (); Ms. Position=0; if(Ms. Length >0) {Ms. WriteTo (context. Response.outputstream); } context. Response.End (); } }}
Because the voice wants to set the vocals, speed, and then synthesize the voice and so on a series of processes, so here to note is the need to call SpeechSynthesizer by means of an asynchronous thread.
Several schemes of text-to-speech in web