Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
Mr/Sir..
I am developing a speech recognition in vb.net. How to code a function when user say something, eg: "CAT", system will reply "CORRECT" .

Here is an example code that i found, but it do not work:
VB
'CODE1)
    Private Sub recognizer_SpeechRecognized(ByVal sender As Object, ByVal e As SpeechRecognizedEventArgs)
    
Dim objSpeechToSpeech As Object
 objSpeechToSpeech = CreateObject("SAPI.spvoice")

Select Case e.Result.Text
         Case "CAT"
         objSpeechToSpeech.Speak("correct")
        End Select
End Sub

VB
'CODE2)

Private Sub DirectSR1_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)
       
      Dim objSpeechToSpeech As Object
      objSpeechToSpeech = CreateObject("SAPI.spVoice")
       If Phrase = "CAT" Then
      objSpeechToSpeech.Speak("Correct")
     End If
    End Sub

Any correction?
Could you help me if there is any other way?

Thank you...
Posted
Updated 12-Dec-10 22:06pm
v2
Comments
Kschuler 13-Dec-10 12:01pm    
What happens when it doesn't work? Do you get an error?
mohan Arjunan 14-Dec-10 13:55pm    
no error.. no output.. its a speech-to-speech actually..user say "CAT", system reply "CORRECT" by speech.. i do not know whether the code i found as above is what i need.. any sugestion? if can post any suggested code.. thank you very much Kschuler,,

1 solution

SpeechRecognizer Class[^]

C#
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    _recognizer = new SpeechRecognizer();
    _recognizer.Enabled = true;
    _recognizer.SpeechRecognized += OnSpeechRecognized;
}
private void OnSpeechRecognized(object sender, SpeechRecognizedEventArgs eventArgs)
{
    if( eventArgs.Result.Text == "cat")
    {
        object spVoice = CreateObject( "SAPI.SpVoice");
        spVoice.Speek( "correct");
    }
}
 
Share this answer
 
v2
Comments
mohan Arjunan 14-Dec-10 13:31pm    
Thank you very much for the reply.. my ques is about speech-to-speech.. where.. when user say "CAT", system will reply "CORRECT" by speech. But according to your code.. if( eventArgs.Result.Text == "cat").. "Text" exist in your code. There is no text in my system.. because im developing learning system for blind people.. comunicating by speeh-to-speech. Is your code is what i need? or any other code for my ques.. thank you Radhakrishnan sir.. reply please..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900