Chen Benfeng Change: lionhttp://www.microsoft.com
Program Download: Click to download the source file: Click to download voice is the most natural interaction method of human beings, but also the highest goal of the development of software user interfaces. Microsoft has actively promoted the development of voice technology, and the speech development platform SPEECH SDK helps developers to achieve voice applications. As the .NET technology is deeply rooted, more and more programmers began to go to the .NET platform for development. However, in the newly released .NET SPEECH SDK, there is no support for Chinese speech. Currently supports Chinese SPEECH SDK's SAPI 5.1 () under the Windows platform, this article describes how to develop SAPI5.1 under the .NET platform. Chinese voice application.
1. SAPI.51 SDK is analyzed and installed SAPI SDK is a free voice application development kit for Microsoft. This SDK contains voice application design interface (SAPI), Microsoft's continuous speech recognition engine (MCSR) and Microsoft's speech synthesis ( TTS) Engine, etc. The current 5.1 version can support three language identification (English, Chinese and Japanese) and 2 language synthesis (English and Chinese). SAPI also includes direct voice management, training wizard, event, grammatical compile, resource, speech recognition (SR) management, and TTS management, SAPI. Its structure is shown in Figure (1): Figure (1) The voice engine interacts through the DDI layer (device driving interface) and SAPI (SPEECHAPI), and the application communicates over the API layer and SAPI. By using these APIs, users can quickly develop applications in speech recognition or speech synthesis. SAPI5.1 SDK can be downloaded from Microsoft website: http://www.microsoft.com/speech/download/SDK51/ The SPEECH SDK 5.1 (68M) and 5.1 Language Pack (81.5m) are required to be installed.
2. Import the COM object to the Windows platform based on .NetsAPI 5.1, the COM interface is called via the COM interface. To apply SAPI5.1 under the .NET platform, we can use the powerful tool TLbimp.exe with the .NET Framework to import the SAPI SDK's COM object into .NET. TLBIMP.EXE produces a controlled packaging class that can use it. Packaging class management actual COM object reference number. When the packaging class is used as a collection of garbage, the package releases the COM object it wrapped. Of course, you can also use the COM object from the project reference dialog in the VS.NET environment, which is also completed by TLBIMP.EXE. The following demonstrates how to import SAPI COM objects: D: / Program Files / Common files / Microsoft Shared / Speech> Tlbimp Sapi.dll / Out: DotNetSpeech.dll
After the SDK, you can find SAPI.dll under the D: / Program Files / Common Files / Microsoft Shared / Speech / Directory, which defines the SAPI COM object, convert the DLL to .NET with the TLbimp.exe tool. Assembly --- DotNetSpeech.dll under the platform, the conversion process will prompt a lot of warnings (Warning), but this impact us can ignore. Finally, we can use ILDASM to view objects in dotnetspeech.dll.
3. Using C # Developing Chinese TTS Application Examples By an instance to introduce how to develop voice applications with C #, the development environment: operating system: Windows 2000 Chinese version sp3.net framework: 1.0.3705 (English) Visual Studio. NET 7.0.9466 (English version) First, create a new C # Windows Application Engineering Speech, add the DotNetSpeech object library in the Solution Explorer on the right side of the development environment. Right-click "Reference", select "Add Reference", find the DotNetSpeech.dll you just generated in the pop-up file selection dialog. Open the FORM1.CS code file, add a namespace to the beginning of the code (accountation case). Using dotNetSpeech; This enables the import of SAPI SDK. We can start writing application code below. This example demonstrates how to read text through the trumpet and transform the text into a speech signal (WAVE sound file), the program interface is shown in Figure (3):
// read private void buttonSynthesis_Click (object sender, System.EventArgs e) {try {SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync; SpVoice Voice = new SpVoice (); Voice.Speak (this.textBoxText.Text, SpFlags);} catch (Exception er) {MessageBox.Show ( "An Error Occured!", "SpeechApp", MessageBoxButtons.OK, MessageBoxIcon.Error);}} // generate a sound file (Wav) private void buttonTTStoWave_Click (object sender, System.EventArgs e) { try {SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync; SpVoice Voice = new SpVoice (); SaveFileDialog sfd = new SaveFileDialog ();. sfd.Filter = "All files (. * *) | * * | wav files (* .wav) | * .wav "; sfd.Title =" Save to a wave file "; sfd.FilterIndex = 2; sfd.RestoreDirectory = true; if (sfd.ShowDialog () == DialogResult.OK) {SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite; SPFileStream SPFileStream = new spfilestream (); spfilestream.open (sfd.filename, spfilemode, false); voice.audiooutputstream = SPFileStream; Voice.Speak (txtSpeakText.Text, SpFlags); Voice.WaitUntilDone (Timeout.Infinite); SpFileStream.Close (); "! An Error Occured"}} catch (Exception er) {MessageBox.Show (, "SpeechApp", MessageBoxButtons .Ok, messageboxicon.error);}} Next, you have to go to the Control Panel to configure the SPEECH SDK engine to process the language. Open "Control Panel", open the "Voice" configuration item, you can see Here we can specify what language can be identified or synthesized, and can also configure related hardware devices and control speed. (Figure 4) Select Microsoft Simplified Chinese in the "Voice Selection" combo box of "Text-Speech Conversion". This can synthesize Chinese characters. Back to VS.NET, F5 Compiles to run the application, enter Chinese characters in the text box, wear the headset, click the "Read" button, start to experience the new generation of smartman interface, huh, huh :)