To develop Chinese voice applications under the .NET platform.

xiaoxiao2021-03-06  39

To develop Chinese voice applications under the .NET platform.

Summary:

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.

table of Contents:

1. SAPI.51 SDK analysis and installation

2. Import COM objects to .NET

3. Develop a Chinese TTS application example with C #

4 Conclusion

5. References

1. SAPI.51 SDK analysis and installation

SAPI SDK is a free Voice Application Development Kit for Microsoft, which 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 driver 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.

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 COM object to .NET

SAPI 5.1 is called by a COM interface based on 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. Developing Chinese TTS Application Examples with C #

By following an example, you will 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 C # Windows Application Engineering Speechapp, 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.

figure 2)

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. Let's start writing application code. 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 ();

}

}

Catch (Exception ER)

{

MessageBox.show ("An Error Occured!", "Speechapp", MessageBoxButtons.ok, MessageBoxicon.ERROR);

}

}

Next, it is also necessary to go to the control panel to configure the SPEECH SDK engine. 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 :)

4. in conclusion

Microsoft provides a powerful platform for voice human interface, and .NET environment makes this development convenient. Hurry to download SAPI5.1 SDK, let your app "painting color", reflect Nature Ui, Let's Go !!!

5. references

[1] SPEECH SDK comes with documentation (SAPI.CHM)

[2] MSDN (MSDN.Microsoft.com)

Author: CHEN Feng

转载请注明原文地址:https://www.9cbs.com/read-118608.html

New Post(0)