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. net speechSDK does not support Chinese Speech. Currently, the highest version of the Speech SDK that supports Chinese is SAPI5.1 () on the Windows platform. 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
SAPISDK is a free speech application development kit provided by Microsoft. This SDK 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 .netplatform, we can use the powerful tool tlbimp.exe of .netframeworkto import the COM Object of SAPISDK 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 \ MicrosoftShared \ Speech \ directory to define the sapicomobject, and use tlbimp.exe to convert 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 select "AddReference". In the pop-up dialog box, find the generated DotNetSpeech. dll.
Figure (2)
Open the Form1.cs code file and 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 ):
// 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)
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)
Author: Chen benfeng
Source: http://www.cnblogs.com/luckeryin/archive/2010/03/15/1685991.html