Develop Chinese speech applications on the Net Platform Program
--------------------------------------------------------------------------------
Abstract:
Voice is the most natural way for humans to interact with each other and the highest goal of software user interface development at present. Microsoft has been actively promoting the development of speech technology, and released the speech development platform speech SDK to help developers implement speech applications.
With the. NET technology gaining popularity, more and more programmers begin to transfer to the. NET platform for development. However, in the newly released. the net speech SDK does not support Chinese speech. Currently, the highest version of the speech SDK that supports Chinese is SAPI 5.1 () on Windows. use sapi5.1 to develop Chinese speech applications.
--------------------------------------------------------------------------------
Directory:
1. Analysis and installation of sapi.51 SDK
2. Import COM objects to. net
3. Use C # To develop a Chinese TTS application example
4. Conclusion
5. References
--------------------------------------------------------------------------------
1. Analysis and installation of sapi.51 SDK
Sapi sdk is a free speech application development kit provided by Microsoft. It contains the speech application design interface (SAPI) and Microsoft's continuous speech recognition engine (MCSR) and Microsoft's speech synthesis (TTS) engine. The current version 5.1 supports recognition in three languages (English, Chinese and Japanese) and synthesis in two languages (English and Chinese ). SAPI also includes powerful design interfaces for low-level control and highly adaptive direct speech management, training wizard, events, syntax compilation, resources, speech recognition (SR) management, and TTS management. Its structure (1 ):
Figure (1)
The Speech Engine interacts with SAPI through the DDI layer (Device Driver Interface), and applications communicate with SAPI through the API layer. By using these APIs, you can quickly develop applications for speech recognition or speech synthesis.
Sapi5.1 sdks can be downloaded from the Microsoft Website: The http://www.microsoft.com/speech/download/sdk51/ requires the setup of speech SDK 5.1 (68 m) and 5.1 Language Pack (81.5 m ).
--------------------------------------------------------------------------------
2. Import COM objects to. net
Sapi5.1 is based on the Windows platform and called through the COM interface. To use sapi5.1 on the. NET platform, we can use the. NET framework's powerful tool tlbimp.exe to import the COM Object of the sapi sdk to. net. Tlbimp.exe generates a controlled packaging class, which can be used by the management client. Number of reference packages for managing the actual COM object. When the packaging class is used as the collection garbage, the packaging class releases the COM object it wraps. Finished.
The following shows how to import the COM Object of SAPI:
D: \ Program Files \ common files \ microsoft shared \ speech> tlbimp SAPI. dll/out: dotnetspeech. dll
After the SDK is installed, you can find sapi.dllin the D: \ Program Files \ common files \ microsoft shared \ speech \ directory, which defines the sapicomobject and converts the DLL. NET platform Assembly --- dotnetspeech. DLL, the conversion process will prompt a lot of warnings (warning), but this affects our development, can ignore. Finally, we can use ildasm to view the objects in dotnetspeech. dll.
--------------------------------------------------------------------------------
3. Use C # To develop a Chinese TTS application example
The following example shows how to use C # To develop a speech application. The development environment is:
Operating System: Windows 2000 Chinese version + SP3
. NET Framework: 1.0.3705 (English version)
Visual Studio. NET 7.0.9466 (English version)
First, create a C # windows application project speechapp and add the dotnetspeech Object Library in Solution Explorer on the right of the development environment. Right-click "Reference" and choose "add reference". In the displayed dialog box, find the generated dotnetspeech. dll.
Screen. width-333) {This. width = screen. width-333; this. title = 'open new window';} "onmouseover =" If (this. title) {This. style. cursor = 'hand';} "; onclick =" If (this. title) {window. open ('HTTP: // www.microsoft.com/china/community/images/techarticleimages/cnspeech2.jpg');} "cnspeech2.jpg? Border = "0">
Figure (2)
Open form1.cs Code File, add a namespace (case sensitive) at the beginning of the Code ).
Using dotnetspeech;
In this way, the sapi sdk is imported. Now we can write the application code. This example shows how to read the text through the speaker and convert the text into a voice signal (wave audio file), the program interface (3 ):
Screen. width-333) {This. width = screen. width-333; this. title = 'open new window';} "onmouseover =" If (this. title) {This. style. cursor = 'hand';} "; onclick =" If (this. title) {window. open ('HTTP: // www.microsoft.com/china/community/images/techarticleimages/cnspeech3.jpg');} "cnspeech3.jpg? Border = "0">
// Read aloud
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 = new spfilestream ();
Spfilestream. Open (SFD. filename, spfilemode, false );
Voice. audiooutputstream = spfilestream;
Voice. Speak (txtspeaktext. Text, spflags );
Voice. waituntildone (timeout. Infinite );
Spfilestream. Close ();
}
}
Catch (exception ER)
{
MessageBox. Show ("an error occured! "," Speechapp ", messageboxbuttons. OK, messageboxicon. Error );
}
}
Next, configure the current language of the speech SDK engine on the control panel. Open "Control Panel", open the "Voice" configuration item, and you can see where we can identify or synthesize the current language, you can also configure related hardware devices and control the language speed. (4)
Screen. width-333) {This. width = screen. width-333; this. title = 'open new window';} "onmouseover =" If (this. title) {This. style. cursor = 'hand';} "; onclick =" If (this. title) {window. open ('HTTP: // www.microsoft.com/china/community/images/techarticleimages/cnspeech4.jpg');} "cnspeech4.jpg? Border = "0">
In the "text-speech conversion" "speech selection" combo box, select Simplified Chinese (Microsoft Simplified Chinese ). In this way, Chinese characters can be merged.
Return to vs. net, F5 compile and run the application just now, enter Chinese characters in the text box, put on headphones, and click "read aloud" to experience the new generation of intelligent man-machine interfaces :)
--------------------------------------------------------------------------------
4. Conclusion
Microsoft provides a powerful platform for Voice Man-machine interfaces. the. NET environment makes this development more convenient and convenient. Download the sapi5.1 SDK and let's go !!!
--------------------------------------------------------------------------------
5. References
[1] Description documentation (SAPI. CHM) provided by the speech SDK)
[2] msdn (msdn.microsoft.com)
--------------------------------------------------------------------------------