I am trying to make a program basically a voice support so that recognizes speech and does the corresponding work I want this program to work even after the pc is in sleep state thats why i want service but after installing service successfully it does not hear any voice.
- public partial class Service1 : ServiceBase
- {
- SpeechSynthesizer s = new SpeechSynthesizer();
- SpeechRecognitionEngine rec = new SpeechRecognitionEngine();
- Choices list = new Choices();
-
- public Service1()
- {
- s.SelectVoiceByHints(VoiceGender.Male)
- s.Speak("heyy");
- list.Add(new String[] { "hello", "how are you" });
- Grammar gr = new Grammar(new GrammarBuilder(list));
- try
- {
- rec.RequestRecognizerUpdate();
- rec.LoadGrammar(gr);
- rec.SpeechRecognized += rec_speachrecocnized;
- rec.SetInputToDefaultAudioDevice();
- rec.RecognizeAsync(RecognizeMode.Multiple);
-
-
- }
- catch { return; };
-
- InitializeComponent();
- }
-
- public void speak(String h)
- {
-
- s.Speak(h);
- }
-
- private void rec_speachrecocnized(object sender, SpeechRecognizedEventArgs e)
- {
- String r = e.Result.Text;
- if (r == "hello")
- {
-
- speak("hello");
- }
-
- if (r == "how are you")
- {
-
- speak("fine");
- }
- }
-
-
- protected override void OnStart(string[] args)
- {
-
- }
-
- protected override void OnStop()
- {
- }
- }