The application of Chinese and English speech synthesis and speech recognition in C # (II.)

Source: Internet
Author: User
Tags empty mixed
However, the method itself does not know what language you are giving the string, so you need us to read the string in what language. The Voice attribute of the Spvoiceclass class is used to set the language, we can get all the list of languages through the Spvoiceclass Getvoices method, and then select the corresponding language according to the parameters, such as setting the language to Chinese as follows:

private void Setchinavoice ()

{

Voice. Voice = Voice. Getvoices (String. Empty,string. Empty). Item (0);

}

0 is used in Chinese, and 1234 in English, which means different accents.

In this way, we set up a language, if combined with the pronunciation method, we can design a only Chinese speech method

private void Speakchina (string strspeak)

{

Setchinavoice ();

Speak (Strspeak);

}

The only way to speak English speech is similar, the above program has.

For a combination of Chinese and English language, we let the program read the mixed speech method is: Programming the language of the Chinese and English separate, to call the Speakchina method, English call Speakenglishi method; As to how to judge whether a character is English or Chinese, I am using the method of judging the ASC code, the concrete class method is implemented through Analysespeak.

In this way, for a piece of Chinese and English mixed text, we simply pass it as a parameter to the Analysespeak, he can complete the mixed pronunciation in English and Chinese.

Of course, for the pronunciation of the tentative, continue, stop and other operations, the above also gives a simple method call, it is easy to understand.



The following is a brief introduction to Chinese speech recognition methods:

First put the class source code for the speech recognition below, and then explain:

public class Sprecognition

{

private static sprecognition _instance = null;

Private Speechlib.ispeechrecogrammar ISRG;

Private Speechlib.spsharedrecocontextclass Ssrcontex =null;

Private System.Windows.Forms.Control CDisplay;

Private Sprecognition ()

{

Ssrcontex = new Spsharedrecocontextclass ();

ISRG = Ssrcontex.creategrammar (1);

Speechlib._ispeechrecocontextevents_recognitioneventhandler Rechandle =

New _ispeechrecocontextevents_recognitioneventhandler (contexrecognition);

Ssrcontex.recognition + = Rechandle;

}

public void Beginrec (Control Tbresult)

{

Isrg. Dictationsetstate (speechrulestate.sgdsactive);

CDisplay = Tbresult;

}

public static Sprecognition instance ()

{

if (_instance = null)

_instance = new Sprecognition ();

return _instance;

}

public void Closerec ()

{

Isrg. Dictationsetstate (speechrulestate.sgdsinactive);

}

private void contexrecognition (int iindex,object obj,speechlib.speechrecognitiontype type, Speechlib.ispeechrecoresult result)

{

Cdisplay.text + = result. Phraseinfo.gettext (0,-1,true);

}



}



We define the context and syntax of Ssrcontex and ISRG for speech recognition, and by setting the Isrg Dictationsetstate method, we can start or end the recognition, which is the Beginrec and Closerec method in the above program. CDisplay is where we use to output recognition results, and to be able to display results on most controls, I use a control class to define it. Of course, every speech recognition triggers the Ispeechrecocontextevents_recognitioneventhandler event, and we define a method contexrecognition to respond to the event, and output the recognition result in this method.



In this way, the Chinese speech processing some of the most basic problems have a simple solution, of course, this method has a lot of imperfect places, I hope that we put forward more criticism and common improvement.




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.