Asp.net implements tts (semi-finished products), asp. nettts

Source: Internet
Author: User

Asp.net implements tts (semi-finished products), asp. nettts

Previously, tts was successfully implemented using WinForm, and the class library of the system was called. However, when I moved the same code to asp.net, I encountered many problems. I checked many websites and tried many methods. Now I have made some of them.

This code was used to call Microsoft's TTS.

1 SpeechSynthesizer speech = new SpeechSynthesizer();2 public void Speak(string text, int rate)3 {4     speech.Rate = rate;5     speech.Speak(text);6     speech.Dispose();7 }

On the webpage, I assigned this method to the click Event of the button. For the first time, there was a sound, but after the sound was played, the webpage was still loading continuously, and then pressed the button. After debugging, we found that the events were all over. I felt very messy. Then I wanted to use Ajax to let it execute and generate the audio file on the background. The file was generated smoothly when I clicked the button for the first time, but there was a problem when I clicked the second one, it took a long time to generate it, just like getting stuck, and a small partner encountered the same problem. First go to the Ajax code:

 1     <script type="text/javascript"> 2         $(document).ready(function() { 3             $("#bt_read").click(function () { 4                 var url = window.location.href + "/TextSpeak"; 5                 $.ajax({ 6                     type: "POST", 7                     url: url, 8                     data: "{'text':'hello'}", 9                     contentType: "application/json;charset=utf-8",10                     dataType: "json",11                     error: function() {12                         alert("error");13                     }14                 });15             });16         })17     </script>

This is the background code:

1     [WebMethod]2     public static void TextSpeak(string text)3     {4         TextToSpeak ttSpeak = new TextToSpeak();5         string x = DateTime.Now.ToString("yyyyMMddHHmmss");6         ttSpeak.SaveWaveFile("d:/" + x + ".wav", text, 1, "male");7     }

(The code for TextToSpeak is in the previous article)

Hope you can see that it helps me solve this problem (if you can't see it, you can only slowly tangle with yourself> _ <) ----- if you want to see the solution, you can ignore the above Code ..

After trying a lot of methods, you can do this (and add a DotNetSpeech. dll class library ):

/// <Summary> /// TTS // </summary> // <param name = "path"> path </param> // <param name = "text"> text </param> /// <param name = "rate"> language speed </param> /// <param name = "gender"> gender </param> public void SaveWaveFile (string path, string text, int rate, string gender) {Type type = Type. getTypeFromProgID ("SAPI. spVoice "); dynamic spVoice = Activator. createInstance (type); // This is mainly used to call DotNetSpeech var obj = spVoice. getVoices (); if (gender. toLower () = "male") {for (int I = 0; I <obj. count; I ++) {string desc = obj. item (I ). getDescription (); if (desc. contains ("Paul") {spVoice. voice = obj. item (I) ;}} else if (gender. toLower () = "female") {for (int I = 0; I <obj. count; I ++) {string desc = obj. item (I ). getDescription (); if (desc. contains ("Kate") {spVoice. voice = obj. item (I) ;}} spVoice. rate = rate; SpeechStreamFileMode spfFileMode = SpeechStreamFileMode. SSFMCreateForWrite; SpFileStream spFileStream = new SpFileStreamClass (); spFileStream. open (path, spfFileMode, false); spVoice. audioOutputStream = spFileStream; spVoice. speak (text); spVoice. waitUntilDone (1000); spFileStream. close ();}

Why didn't I write the speak method .. You need to play the audio on the webpage client to make the server speak useful. The server shouted dumb, and the client could not hear it ~~ Only audio files can be generated and uploaded to the webpage for playing using plug-ins. Why am I a semi-finished product? I have tried many methods and cannot find a suitable plug-in to solve the playback problem.

The plugin must meet these two conditions:

1. dynamically add links.

2.x. WAV format.

I 've tried the mediaPlayer plug-in written with custom controls for playback reference: http://www.cnblogs.com/insus/archive/2009/05/03/1448097.html

In fact, this can solve all the problems .. That is, it only works on ie, but not on other browsers .. After reading the webpage code, all Audio links are read but cannot be played ~~

Another method is to enable the swf player to play the wav file generated by tts or convert the wav file to MP3 .. I have not implemented this yet.

First, I am still debugging it. When it comes, I will try it out .. I also hope you can help me solve this problem ~~

 

 


I want to create an asp and net website. I want to teach my homework a semi-finished product and a full version of this semi-finished product.

Is it just a small website?
Are you sure you want to submit a news publishing system for a short time. Download an Artisteer,
Generate a static HTML page and copy the code.
Modify the text section.
Drag two ListView instances.

How does aspnet implement website statistics?

If you don't want to write it on your own, there is no doubt that you can use the traffic statistics in the webmaster tool to register, get the code, and paste it on your website!

If you want to write it by yourself, there are many ways to do this,
In the Application_start event of the Global application (Global. asax), the visit time will be the ip writer xml file, txt file or database, and then the analysis and statistics will be OK.

Related Article

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.