Asked by:
C# Console Application- How to detect the mic input?

Question
-
I'm working on a program that converts what I say to a text on screen. That's the code I wrote up to now:
engine = new SpeechRecognitionEngine(); engine.SetInputToDefaultAudioDevice(); Grammar g = new DictationGrammar(); engine.LoadGrammar(g); engine.RecognizeAsync(RecognizeMode.Multiple); engine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(engine_SpeechRecognized); Console.ReadLine();
static void engine_SpeechRecognized(object ob, SpeechRecognizedEventArgs e) { Console.WriteLine(e.Result.Text); }
When I tried to run the program an error message popped up on the SetInputToDefaultAudioDevice() line and said "No recognizer is installed".
I believe that the problam is that the computer doesn't recognize the microphone that is connected to it. Can you help me to fix this problem?
Edit: Nevermind I just found out that the reason why I couldn't run the program is because of my main Windows language.
- Edited by yuvalmus Monday, August 27, 2018 2:42 PM
All replies
-
Hi yuvalmus,
Thank you for posting here.
For your question, if you want to convert what you say to a text, you could try the example speech to text below.
For better understanding, I user a form to display.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Speech.Recognition; namespace speech_to_text { public partial class Form1 : Form { public Form1() { InitializeComponent(); button1.Text = "Click and then speak"; } private void button1_Click(object sender, EventArgs e) { SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine(); Grammar dictationGrammar = new DictationGrammar(); recognizer.LoadGrammar(dictationGrammar); try { button1.Text = "Speak Now"; recognizer.SetInputToDefaultAudioDevice(); RecognitionResult result = recognizer.Recognize(); textBox1.Text = result.Text; } catch (InvalidOperationException exception) { button1.Text = String.Format("Could not recognize input from default aduio device. Is a microphone or sound card available?\r\n{0} - {1}.", exception.Source, exception.Message); } finally { recognizer.UnloadAllGrammars(); } } } }
Best Regards,
Wendy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com. -
-
Hi yuvalmus,
Thank you for feedback and sorry for late reply.
If you want to use speech to text on console, you could download the source file from code project for reference.
https://www.codeproject.com/Articles/483347/Speech-recognition-speech-to-text-text-to-speech-a
Best Regards,
Wendy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com. -