C # Create a simple app like Siri's voice quiz

Source: Internet
Author: User

With the. NET Speech recognition Library, it's easy to make simple question-and-answer programs like Siri.

The implementation steps are as follows:

1. Create a new project and add a reference to the System.speech. (as shown)

2. Define speech recognition (speechrecognitionengine) and voice reading (SpeechSynthesizer) separately in the window

Speechrecognitionengine _recognizer = new Speechrecognitionengine (); SpeechSynthesizer Siri = new SpeechSynthesizer ();

3. Add the following code to the form launch:

 CultureInfo            Myciintl = new CultureInfo ("ZH-CN"); foreach (Recognizerinfo config in speechrecognitionengine.installedrecognizers ()) {if (config.c Ulture. Equals (myciintl) && config.                    Id = = "Ms-2052-80-desk") {_recognizer = new speechrecognitionengine (config);                Break }} _recognizer.            Setinputtodefaultaudiodevice (); _recognizer. Loadgrammar (New Grammar new Grammarbuilder (New Choices (File.ReadAllLines (Application.startuppath + "\\command.txt")            )))); _recognizer.            speechrecognized + = new eventhandler<speechrecognizedeventargs> (_recognizer_speechrecognized); _recognizer. Recognizeasync (recognizemode.multiple); 
void _recognizer_speechrecognized (object sender, Speechrecognizedeventargs e) {string speech            = E.result.text;                    Switch (speech) {case "Hello": Siri.speak ("Hello");                Break                    Case "Today's Day of the Week": Siri.speak ("Today" + DateTime.Today.ToString ("dddd"));                Break                    Case "Date Today": Siri.speak ("Today is" + DateTime.Today.ToString ("Yyyy-mm-dd"));                Break                    Case "What's The Time": DateTime now = DateTime.Now; String time = Now.                    Getdatetimeformats (' t ') [0];                    Siri.speak (time);                               Break                    Case "Shutdown": System.Diagnostics.Process.Start ("Shutdown", "-S");                           Break }        }

All commands are saved in the "Command.txt" file, remember to use Unicode to save the line.

Run the program and you can implement the Voice quiz.

The program can also be applied to the use of voice control home appliances, the realization of smart Home (reference http://blog.csdn.net/soft2buy/article/details/6248333).


Complete code download for this article:


C # Create a simple app like Siri's voice quiz

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.