Are you blogging on PH? Get your free blog.

VB.NET

Moderators: seancampbell
Number of threads: 3618
Number of posts: 9200

This Forum Only
Post New Thread

Report
sapi 5.1 in vb.net problem!! voice program Posted by kaex21 on 7 Nov 2009 at 12:16 AM
hello to everyone.. i having a problem with my program.. it seem like it wont detect a voice.. my program is all about ordering a food in the restaurant via voice commands.. i used notepad instead of xml.. can you help me?? thank you in very much.. your reply is very much appriciated..

here's my code..











Public gmode As Integer
Public gRestoreGrammar As Boolean
Public additional As Boolean

Private Sub AxDirectSR1_PhraseFinish(ByVal flags As Long, ByVal beginhi As Long, ByVal beginlo As Long, ByVal endhi As Long, ByVal endlo As Long, ByVal Phrase As String, ByVal parsed As String, ByVal results As Long)
If (parsed = "") Then
AxDirectSR1.Deactivate()
If (Rnd() > 0.5) Then
AxDirectSS1.Speak("kindly repeat your order again sir.")
Else
AxDirectSS1.Speak("please follow the menu.")
End If
Else
If (parsed = "ok") Then
AxDirectSR1.Deactivate()
If (additional = False) Then
gmode = 2
AxDirectSS1.Speak("Would like to have drinks?")

Else
gmode = 3
AxDirectSS1.Speak("would that be all sir?")
End If
ElseIf (parsed = "cancel") Then
Dim Item As String
Item = ListBox1.Items.Count - 1
If (Item >= 0) Then
ListBox1.Items.Remove(ListBox1.Items.Count - 1)
AxDirectSR1.Deactivate()
AxDirectSS1.Speak("your order cancel")
End If
ElseIf (parsed = "no") Then
If (gmode = 2) Then
gmode = 3
additional = True
AxDirectSR1.Deactivate()
AxDirectSS1.Speak("verifying your order")
ElseIf (gmode = 3) Then
gmode = 0
gRestoreGrammar = True
AxDirectSR1.Deactivate()
AxDirectSS1.Speak("you can continue your order")
Else
gmode = 0
gRestoreGrammar = True
End If
ElseIf (parsed = "yes") Then

If (gmode = 2) Then
'form2.Show()
gmode = 3
AxDirectSR1.Deactivate()
AxDirectSS1.Speak("would that be all")

ElseIf (gmode = 3) Then
Dim total As Integer
total = 0
For i = 0 To ListBox1.Items.Count - 1
total = total + Val(ListBox1.Items(i))
Next i
ListBox1.Items.Add("---total is: $" + Format(total, "###0.00"))
gmode = 1
gRestoreGrammar = True

AxDirectSR1.Deactivate()

AxDirectSS1.Speak("Your total will be $" + Format(total, "###0.00") + " at the next window please.")
End If
Else
AxDirectSR1.Deactivate()
ListBox1.Items.Add(parsed)
End If
End If

ListBox1.SelectedIndex = ListBox1.Items.Count - 1
AxDirectSS1.Speak(Phrase)

End Sub
Private Sub DirectSS1_AudioStop(ByVal hi As Long, ByVal lo As Long)
If (gmode = 1) Then
ListBox1.Items.Clear()
gmode = 0
AxDirectSS1.Speak("Hi! May I take your order?")
Else
If (gmode = 2) Or (gmode = 3) Then
'HighLightOrder (False)
AxDirectSR1.GrammarFromFile("C:\Documents and Settings\kaex21\My Documents\Visual Studio 2008\Projects\Project1\WindowsApplication6\WindowsApplication6\yesno.txt")

ElseIf (gRestoreGrammar) Then
'HighLightOrder (True)
AxDirectSR1.GrammarFromFile("C:\Documents and Settings\kaex21\My Documents\Visual Studio 2008\Projects\Project1\WindowsApplication6\WindowsApplication6\menu.txt")
gRestoreGrammar = False

End If
REM we had to turn off listening before talking, so now that we are done talking we
REM should start listening again
AxDirectSR1.Activate()
End If
End Sub

Private Sub main_Terminate()
AxDirectSR1.Deactivate()
End Sub
Private Sub main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
gmode = 0
gRestoreGrammar = False

End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
On Error GoTo GeneralFail
REM we just use this function once, on the first callback, then the timer isn't needed anymore
Timer1.Enabled = False
Dim engine As String
REM Initialize the recognizer. We want command and control, so find and select that engine (or best match)
AxDirectSR1.Initialized = 1

engine = AxDirectSR1.Find("MfgName=Microsoft;Grammars=1")
AxDirectSR1.Select(engine)

REM Burger.txt is our uncompiled grammar. Compile and load it now.
'HighLightOrder(True)
'AxDirectSR1.GrammarFromFile(app.path + "\menu.txt")
AxDirectSR1.GrammarFromFile("C:\Documents and Settings\kaex21\My Documents\Visual Studio 2008\Projects\Project1\WindowsApplication6\WindowsApplication6\menu.txt")
REM Now load the synthesizer, find and select any female voice from microsoft
Dim voice As String
voice = AxDirectSS1.Find("MfgName=Microsoft;Gender=2")
AxDirectSS1.Select(voice)

REM Start the voice interface...control goes to DirectSS1_AudioStop after this is said, gMode=0
AxDirectSS1.Speak("Welcome to kaex restaurant, sit back and enjoy as you take your order.")

REM sometimes the vb environment comes to front while we're loading, so take the screen back
Me.Show()
GoTo done
GeneralFail:
MsgBox("Unable to start using text to speech or recognition.")
done:
End Sub



 
Popular resources and forums for programmers on Programmersheaven.com
Assembly, Basic, C, C#, C++, Delphi, Java, JavaScript, Pascal, Perl, PHP, Python, Ruby, Visual Basic
© Copyright 2009 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin. Read the latest words from the publisher here.
Be the first to sign up for Lars Hagelin’s In-depth Outsourcing Newsletter here.
bootstrapLabs Logo A bootstrapLabs project.