I'm trying to create a Speech Recognition program, that needs to run on a locked Windows computer, as part of a Home Automation project. But it seems that the SpeechRecognitionEngine stops recognizing when the computer is locked (and continues when the computer is unlocked).
My current test program looks like this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Speech.Recognition;
using System.Globalization;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
SpeechRecognitionEngine sre;
public Form1()
{
InitializeComponent();
CultureInfo ci = new CultureInfo("en-us");
sre = new SpeechRecognitionEngine(ci);
sre.SetInputToDefaultAudioDevice();
GrammarBuilder gb = new GrammarBuilder("Hello");
sre.LoadGrammarAsync(new Grammar(gb));
sre.SpeechRecognized += sre_SpeechRecognized;
sre.RecognizeAsync(RecognizeMode.Multiple);
}
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
listBox1.Items.Add(DateTime.Now.ToString() + " " + e.Result.Text);
}
}
}
I'm wondering if it's possible to change the input of the SpeechRecognitionEngine (perhaps using the SetInputToAudioStream
or SetInputToWaveStream
methods) to a live audio stream of the microphone input, and that way work around the problem. Because it seems that the microphone is not turned off when the computer (tried with the SoundRecorder).
Unfortunately I have not been able to find a way to get a live stream of the mic input.