A simple web page read string SpeechLib, read string speechlib
// Reference component: Interop. SpeechLib. dll
// Import space: SpeechLib
// Reference component: Interop. SpeechLib. dll
// Import space: SpeechLib
Reference others' blogs with the preceding settings
// 1. SpVoice voice = new SpVoice ();
// 2. voice. Speak (txt. Text, SpeechVoiceSpeakFlags. SVSFDefault); // read aloud simultaneously
// 3. voice. Speak (txt. Text, SpeechVoiceSpeakFlags. SVSFlagsAsync); // asynchronous reading
// Voice. Voice = voice. GetVoices (string. Empty, string. Empty). Item (0); // set Chinese speech
// Voice. Voice = voice. GetVoices (string. Empty, string. Empty). Item (1); set the English Speech
// Error modification: the error "SpeechLib. SpVoiceClass" cannot be embedded in VS2010 ". Use the applicable interface instead.
// Solution: Right-click the dll introduced in the project, select properties, and set "embedded interoperability type" to False.
// The error message is from HRESULT: 0x800100003. Generally, Windows Audio service is disabled, especially Windows Audio Service is disabled by win2003 by default.
// 1) check that the Windows Audio (AudioSrv) service starts.
// Enter cmd and enter net start AudioSrv
// 2) the sound card driver is successfully installed. "
The powerful feature is that TTS can recognize XML tags. By adding XML tags to texts, we allow TTS to read sentences that are more in line with language reading habits. For example:<volume level="60"> </Volume> set the volume of text reading;<rate absspeed="1"/>、<rate speed="5"/> Set the absolute speed and relative speed of text reading;<pitch absmiddle="2"/>、<pitch middle="5"/> It is used to set the absolute and relative tones for reading the text;<Emph> </emph> sentences between them are considered as emphasized;<Spell> </spell> you can spell words by letter;<silence msec="500"/> Indicates that the voice is stopped and kept in 500 microseconds;<context id="date_mdy"> 02/03/07 </context> you can read the date as required<voice required="Language=409"> </Voice> set the language used for reading aloud. 409 indicates English, 804 indicates Chinese, and 411 indicates Japanese.Background: 1 public ActionResult speak (string speechSounds) 2 {3 SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags. SVSFlagsAsync; 4 SpVoice spVoice = new SpVoice (); 5 spVoice. rate = spVoice. rate-5; 6 if (spVoice. volume <100) 7 {8 spVoice. volume = spVoice. volume + 10; 9} 10 11 if (spVoice. volume> 9) 12 {13 spVoice. volume = spVoice. volume-10; 14} 15 spVoice. speak ("<lang langid = \" 804 \ ">" + speechSounds + "alarm </lang>", SpFlags); 16 return Content ("successful"); 17}View CodeFront end: 1 function a () {2 var url = '/Alarm/speak'; 3 var speechSounds = "your sword is my sword dfdf1234567899652554412235441235" 4 $. ajax ({5 type: "POST", 6 7 url: url, 8 data: {speechSounds: speechSounds}, 9 success: function (msg) {10 11} 12 13 })View Code |