Saturday, April 5, 2008

Robot will repeat whatever you say



Aim of this project:
Robot will repeat whatever you say. It is voice reorganization project.

Main Title: Voice Recognition
Project: Robot will repeat whatever you say.
Developer: Md. Redwanur Rahman
Location: Dhaka, Bangladesh.
Date: 20 February, 2008



Helps:
You need to install SAPI, Genie.exe, go to http://www.microsoft.com/speech/download/sdk51/ and download sapi5.1 & also download Voice agent genie.exe

Setup:
To use this get and install the sapi 5.1, free from microsoft
Then go to control panel, speech. Configure the microphone
(You may have to go to the volume control at the bottom of your screen and unmute the Line in)
Run the training session (you may have to add a new profile)
Make sure it is very quiet around you
Be sure to turn off the microphone, Line in after using this or it will
Click on genie.exe to install.

Program Details:
Option Explicit
Dim WithEvents RecoContext As SpSharedRecoContext
Dim Grammar As ISpeechRecoGrammar
Dim m_bRecoRunning As Boolean
Dim m_cChars As Integer
Dim vol As Double ' this helps open the volume control
Dim bye As Integer 'this closes the volume control
Dim char As IAgentCtlCharacterEx

Private Sub btnend_Click()
char.Stop
End
End Sub

Private Sub Command1_Click()
char.Speak ("Say note, i will open notpad for you.")
char.Speak ("Say Green, Look behind me, colour will change.")
End Sub

Private Sub Form_Load()
Dim anim As String
SetState False
m_cChars = 0
anim = "genie"
Agent1.Characters.Load anim, anim & ".acs"
Set char = Agent1.Characters(anim)
char.MoveTo 520, 300
char.Show
char.AutoPopupMenu = False
char.Speak ("Talk, I can repeat whatever you say, please 1st say Start")
End Sub

Private Sub btnStart_Click()
Debug.Assert Not m_bRecoRunning
char.Speak ("Say any word.")
' Initialize recognition context object and grammar object, then
' start dictation
If (RecoContext Is Nothing) Then
Debug.Print "Initializing SAPI reco context object."
Set RecoContext = New SpSharedRecoContext
Set Grammar = RecoContext.CreateGrammar(1)
Grammar.DictationLoad
End If
Grammar.DictationSetState SGDSActive
SetState True
End Sub

Private Sub btnStop_Click()
Debug.Assert m_bRecoRunning
Grammar.DictationSetState SGDSInactive
SetState False
End Sub

Private Sub Form_Unload(Cancel As Integer)
Char.stop
End Sub

' This function handles Recognition event from the reco context object.
' Recognition event is fired when the speech recognition engines recognizes
' a sequences of words.
Private Sub RecoContext_Recognition(ByVal StreamNumber As Long, _
ByVal StreamPosition As Variant, _
ByVal RecognitionType As SpeechRecognitionType, _
ByVal Result As ISpeechRecoResult _
)
Dim strText As String
'this is to open the notepad
Dim RetVal As Double
strText = Result.PhraseInfo.GetText
'do what you want for various words here
If strText = "green" Then Label1.BackColor = vbGreen
If strText = "red" Then Label1.BackColor = vbRed
If strText = "yellow" Then Label1.BackColor = vbYellow
If strText = "black" Then Label1.BackColor = vbBlack
'this is to end the program by saying by
If strText = "by" Then
MsgBox ("Bye bye.")
End
End If
'1 is normal, 3 is maximized 6 is minimized
If strText = "not" Then RetVal = Shell("c:\windows\notepad.exe", 3)
StreamNumber & ", " & StreamPosition
' Append the new text to the text box, and add a space at the end of the
' text so that it looks better
txtSpeech.SelStart = m_cChars
txtSpeech.SelText = strText & " "
m_cChars = m_cChars + 1 + Len(strText)
char.Speak (strText)
End Sub

' This function handles the state of Start and Stop buttons according to
' whether dictation is running.
Private Sub SetState(ByVal bNewState As Boolean)
m_bRecoRunning = bNewState
btnStart.Enabled = Not m_bRecoRunning
btnStop.Enabled = m_bRecoRunning
End Sub

Others help email: redu0007@yahoo.com
Others effective web: www.geocities.com/redu0007

1 comment:

Getting said...

Very Good Project.
But the source code is no longer available.
Please make a note of that..

Thanks
Prodip