Several schemes of text-to-speech in web

Source: Internet
Author: User

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

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.