I know I'm trying to do something above my level for now, but I'm still trying my best, nevertheless.
Until now I was focused on c++
->Code::Blocks
, highschool level, but now I tried messing around in Visual Studio until I joined a project.
I have some problems with a loop (the program is based on system speech, system speech synthesis, speech recognizer and process start).
I have 2 cases :
1)Inputing the vocal command "hi
" -> it responds back with "hi
".
2)Inputting "hello
" -> it responds with "opening google" & opens that speciffic webpage.
Well, if it would work as it is supposed to. If I input "hi", it responds with "hi"->[ "opening google"+opening the page ]->in a loop
If I input "hello
" it goes straight to the loop [ "opening google"+opening the page]
I tried some break points to see what am I doing there, but I'm hopeless.
You have the code here :
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.Synthesis;
using System.Speech.Recognition;
using System.Diagnostics;
namespace Command
{
public partial class Speech : Form
{
SpeechSynthesizer s = new SpeechSynthesizer();
public Speech()
{
InitializeComponent();
SpeechRecognitionEngine reco = new SpeechRecognitionEngine();
Choices list = new Choices();
list.Add(new string[] { "hi", "hello" });
Grammar gm = new Grammar(new GrammarBuilder(list));
try
{
reco.RequestRecognizerUpdate();
reco.LoadGrammar(gm);
reco.SpeechRecognized += Reco_SpeechRecognized;
reco.SetInputToDefaultAudioDevice();
reco.RecognizeAsync(RecognizeMode.Multiple);
}
catch { }
}
private void Reco_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
string a = e.Result.Text;
switch (a)
{
case ("hello"):
{
s.SpeakAsync("opening google");
Process.Start("https://www.google.com");
break;
}
case ("hi"):
{
s.SpeakAsync("hi");
break;
}
}
}
}
}