Application of Chinese speech recognition technology in c # (I)

Source: Internet
Author: User
Tags sapi

In. net, but the support for Chinese speech has not yet been added, we want to achieve Chinese pronunciation or Chinese speech recognition, you must first install Microsoft's Speech Application SDK (SASDK). The latest version is SAPI 5.1, which can recognize Chinese, Japanese, and English languages. You can download it here:Http://www.microsoft.com/speech/download/sdk51/, requiredTo install the Speech SDK 5.1 and 5.1 Language Pack files, you can select the supported Language for the 5.1 Language Pack Installation.

After the installation, we can start the development of the speech program. Of course, before that, we need to add SAPI. dll to the reference through the example shown in.

Below we design a class that can read both Chinese and English languages:

We will implement this class in singleton mode. The code of the class is as follows, which will be explained in detail:

Public class Speach

{

Private static Speach _ Instance = null;

Private SpeechLib. SpVoiceClass voice = null;

Private Speach ()

{

BuildSpeach ();

}

Public static Speach instance ()

{

If (_ Instance = null)

_ Instance = new Speach ();

Return _ Instance;

}

Private void SetChinaVoice ()

{

Voice. Voice = voice. GetVoices (string. Empty, string. Empty). Item (0 );

}

Private void SetEnglishVoice ()

{

Voice. Voice = voice. GetVoices (string. Empty, string. Empty). Item (1 );

}

Private void SpeakChina (string strSpeak)

{

SetChinaVoice ();

Speak (strSpeak );

}

Private void SpeakEnglishi (string strSpeak)

{

SetEnglishVoice ();

Speak (strSpeak );

}

Public void AnalyseSpeak (string strSpeak)

{

Int iCbeg = 0;

Int iEbeg = 0;

Bool IsChina = true;

For (int I = 0; I <strSpeak. Length; I ++)

{

Char chr = strSpeak [I];

If (IsChina)

{

If (chr <= 122 & chr> = 65)

{

Int iLen = I-iCbeg;


 

String strValue = strSpeak. Substring (iCbeg, iLen );

SpeakChina (strValue );

IEbeg = I;

IsChina = false;

}

}

Else

{

If (chr> 122 | chr <65)

{

Int iLen = I-iEbeg;

String strValue = strSpeak. Substring (iEbeg, iLen );

This. SpeakEnglishi (strValue );

ICbeg = I;

IsChina = true;

}

& Nb

Related Article

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.