In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today Xiaobian to share with you how to achieve speech recognition function based on C#related knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you read this article after some harvest, let's learn about it together.
In. NET 4.0, I was able to get the computer to recognize our voice with the System.Speech component.
Above, when I say "name," it says "Darren," and I say "age," it says "forever 21." How?
First of all, you need to turn on the voice recognition function of the computer.
Right-click the speaker at the bottom right of your computer and select Recording Devices.
Click the default "microphone" and then click the "configure" button in the lower left corner.
Create a form application in VS with a RichTextBox and 2 Buttons on the interface.
Add a reference to System.Speech.
(PS: Emphasize that if you do not turn on speech recognition, the startup program will report an error: speech recognition is not available on this system. SAPI and speech recognition engine not found.)
Write as follows:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Speech.Recognition;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsForms{ public partial class Form1 : Form { SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine(); public Form1() { InitializeComponent(); } private void btnEnable_Click(object sender, EventArgs e) { recEngine.RecognizeAsync(RecognizeMode.Multiple); btnDisable.Enabled = true; } private void Form1_Load(object sender, EventArgs e) { Choices preCmd = new Choices(); preCmd.Add(new string[] { "name", "age" }); GrammarBuilder gb = new GrammarBuilder(); gb.Append(preCmd); Grammar gr = new Grammar(gb); recEngine.LoadGrammarAsync(gr); recEngine.SetInputToDefaultAudioDevice(); recEngine.SpeechHypothesized += RecEngine_SpeechHypothesized; } private void RecEngine_SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e) { switch (e.Result.Text) { case "name": txtList.Text += "\nDarren"; break; case "age": txtList.Text += "\n Forever 21"; break; default: break; } } private void btnDisable_Click(object sender, EventArgs e) { recEngine.RecognizeAsyncStop(); btnDisable.Enabled = false; } }} The above is all the content of this article "How to realize speech recognition function based on C#", thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.