Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
Why the speak appears before the switching of picture.
tan shen
7y
179
1
Reply
SpeechSynthesizer ss =
new
SpeechSynthesizer();
PromptBuilder pb =
new
PromptBuilder();
SpeechRecognitionEngine sre =
new
SpeechRecognitionEngine();
Choices clist =
new
Choices();
int
counter = 0;
int
counter_CorrectAns = 0;
public
void
Question()
{
string
path = @
"C:\Users\Tan Wei Shen\Desktop\FYP\New folder\"
;
string
[] filePaths = Directory.GetFiles(path,
"*.jpg"
);
pictureBox1.Image = Image.FromFile(filePaths[counter]);
ss.SpeakAsync(
"What is this?"
);
clist.Add(
new
string
[] {
"apple"
,
"chicken"
,
"eraser"
});
Grammar gr =
new
Grammar(
new
GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message,
"Error"
);
}
}
private
void
WellDone()
{
timer1.Start();
sre.RecognizeAsyncStop();
label1.Visible =
false
;
string
path = @
"C:\Users\Tan Wei Shen\Desktop\FYP\correct\"
;
string
[] filePaths = Directory.GetFiles(path,
"*.png"
);
pictureBox1.Image = Image.FromFile(filePaths[counter_CorrectAns]);
ss.Speak(
"Well done"
);
counter++;
}
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
}
private
void
sre_SpeechRecognized(
object
sender, SpeechRecognizedEventArgs e)
{
switch
(e.Result.Text.ToString())
{
case
"apple"
:
WellDone();
break
;
case
"chicken"
:
WellDone();
break
;
case
"eraser"
:
WellDone();
break
;
}
}
private
void
btnStart_Click(
object
sender, EventArgs e)
{
btnStart.Visible =
false
;
label1.Visible =
true
;
pictureBox1.Visible =
true
;
Question();
}
private
void
timer1_Tick(
object
sender, EventArgs e)
{
Question();
timer1.Stop();
}
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Getting error while using OpenXML for Excel Export
How to access dynamically created Textbox ID in asp.net c#