. NET Development Chinese speech application

Source: Internet
Author: User
Tags garbage collection interface net reference version wrapper microsoft website visual studio
With the popularity of. NET technology, more and more programmers are starting to go to the. NET Platform for Development. However, in the newly released. NET Speech SDK, there is no support for Chinese speech, and the speech SDK currently supports the highest version of SAPI 5.1 () under the Windows platform. This article describes how to develop Chinese voice applications using SAPI5.1 under the. NET Platform.
--------------------------------------------------------------------------------
Directory:
1. sapi.51 SDK Analysis and installation
2. Import COM objects to. Net
3. Developing a Chinese TTS application with C # sample
4. Conclusion
5. Reference documents
--------------------------------------------------------------------------------
1. SAPI.51 SDK Analysis and installation
The SAPI SDK is a free speech application development Kit from Microsoft, which includes the Voice application Design Interface (SAPI), Microsoft's Continuous speech recognition engine (MCSR), and Microsoft's TTS engine, among others. The current version 5.1 can support the recognition of 3 languages (English, Chinese and Japanese) and the synthesis of 2 languages (English and Chinese). The SAPI also includes powerful design interfaces for low-level control and highly adaptable direct speech management, training wizards, events, syntax compilation, resources, speech recognition (SR) management, and TTS management. The structure of the diagram (1):
Figure (1)
The speech engine interacts through the DDI layer (device-driven interface) and SAPI (SPEECHAPI), and the application communicates through the API layer and SAPI. By using these APIs, users can quickly develop applications in speech recognition or speech synthesis.
The SAPI5.1 SDK can be downloaded from the Microsoft website: http://www.microsoft.com/speech/download/sdk51/requires the installer to have Speech SDK 5.1 (68M) and 5.1 Language Pack (81.5M).
--------------------------------------------------------------------------------
2. Import COM objects to. Net
SAPI5.1 based on the Windows platform, called through the COM interface. To apply SAPI5.1 under the. NET Platform, we can import the SAPI SDK's COM objects into. NET using the powerful tool TlbImp.exe from the. NET Framework. TlbImp.exe produces a regulated wrapper class that the admin client can use. The wrapper class manages the reference number of the actual COM object. When the wrapper class is treated as garbage collection, the wrapper class releases the COM object it wraps. Of course, you can also implement COM objects by selecting COM objects from the Project Reference dialog box in the Vs.net environment, which is also done through TlbImp.exe.
The following shows how to import a sapi COM object:
D:\Program Files\Common Files\Microsoft Shared\speech>tlbimp Sapi.dll/out:dotnetspeech.dll

After the SDK, you can D:\Program Files\Common Files\Microsoft Shared\speech\ The directory below finds SAPI.dll, which defines the SAPI COM object and converts the DLL to the assembly---DotNetSpeech.dll under the. NET Platform using the Tlbimp.exe tool, which prompts a number of warnings (warning But this affects our development and can be ignored. Finally, we can use ILDASM to view the objects inside the DotnetSpeech.dll.
--------------------------------------------------------------------------------
3. Developing a Chinese TTS application sample with C #
The following is an example of how to use C # to develop voice applications, the development environment is:
Operating system: Windows 2000 Chinese + SP3
. Net framework:1.0.3705 (English version)
Visual Studio.NET 7.0.9466 (English edition)
First, create a new C # Windows application Engineering Speechapp, and add Dotnetspeech object libraries to the solution Manager (Solution Explorer) on the right side of the development environment. Right-click on "Reference" (Reference), select "Add Reference" (add Reference), in the Pop-up File selection dialog box to find just the generated DotNetSpeech.dll.

Figure (2)
Open the Form1.cs code file and add the namespace (note case) at the beginning of the code.
Using Dotnetspeech;
This enables the SAPI SDK to be imported, so we can start writing the application code. This example shows how to read text through a trumpet and convert text to a speech signal (wave sound file), and the program interface is shown in Figure (3):

The following are the referenced contents:

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 sound files (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 ();
}
}
catch (Exception er)
{
MessageBox.Show ("An Error occured!", "Speechapp", MessageBoxButtons.OK, Messageboxicon.error);
}
}


Next, you go to the Control Panel to configure the language that the Speech SDK engine is currently working on. Open Control Panel, open the Speech configuration project, where we can specify what languages are currently available for identification or compositing, and configure the relevant hardware devices and control speed. (Figure 4)

Select Simplified Chinese (Microsoft Simplified Chinese) in the Speech selection combo box in text-Speech conversion. So you can synthesize Chinese characters.
Back to Vs.net,f5 compile run just the application, in the text box input Chinese characters, put on headphones, click the "read aloud" button, began to experience a new generation of intelligent Man-machine Interface bar, hehe:
--------------------------------------------------------------------------------
4. Conclusion
Microsoft provides a powerful platform for voice interface, and the. NET environment makes this development easier and faster. Go and download the SAPI5.1 SDK and make your app "vivid", embodying the nature Ui,let ' s go!
--------------------------------------------------------------------------------

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.