Sunday, June 22, 2008

Voice Control windows


Main Title: Voice Interface
Project: Voice Control windows programming code
Developer: Md. Redwanur Rahman
Location: Dhaka, Bangladesh.
Date: 19 September, 2007

To develop computer programming knowledge follow the below voice control windows code.

Aim of this project:
You can control windows using this program

Needed components:
Microphone, SAPI 4 or SAPI 5.1 (Sound application programming Interface)
Use below Components control from SAPI
1. Microsoft Direct speech recognition
2. Microsoft Direct text-to-Speech
For active this two components go to visual Basic Project menu then components then control tab.


Program Details:

Dim Temp As Variant
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2

Private Const VK_Backspace = &H8
Private Const VK_Tab = &H9
Private Const VK_Shift = &H10
Private Const VK_Control = &H11
Private Const VK_Alter = &H12
Private Const VK_Pause = &H13
Private Const VK_CapsLock = &H14
Private Const VK_Return = &HD
Private Const VK_Lshift = &HA0
Private Const VK_Rshift = &HA1
Private Const VK_Rcontrol = &HA
Private Const VK_Escape = &H1B
Private Const VK_Space = &H20
Private Const VK_End = &H23
Private Const VK_Home = &H24
Private Const VK_Left = &H25
Private Const VK_Up = &H26
Private Const VK_Right = &H27
Private Const VK_Down = &H28
Private Const VK_Insert = &H2D
Private Const VK_Delete = &H2E
Private Const VK_F1 = &H70
Private Const VK_F2 = &H71
Private Const VK_F3 = &H72
Private Const VK_F4 = &H73
Private Const VK_F5 = &H74
Private Const VK_F6 = &H75
Private Const VK_F7 = &H76
Private Const VK_F8 = &H77
Private Const VK_F9 = &H78
Private Const VK_F10 = &H79
Private Const VK_F11 = &H7A
Private Const VK_F12 = &H7B
Private Const VK_NumLock = &H90
Private Const VK_ScrollLock = &H91

Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)


Private Sub Form_Load()
Dim FileN As String
FileN = App.Path & "commands.txt"
SR.Deactivate
SR.GrammarFromFile FileN
SR.Activate
SR.AutoGain = 99
CMD_List
End Sub

Private Sub SR_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)

Debug.Print Phrase
If Trim(Phrase) = "" Then
Exit Sub
Else
Text2.Text = Trim(Phrase)
SelMSG (Phrase)
Process_Message (Trim(Phrase))
End If
End Sub


Function Process_Message(Msg As String)
Select Case (UCase(Msg))
Case ("CLOSE")
Call Close_window
Case ("START")
Call Start
Case ("GO")
Call Start
Case ("UP")
keybd_event VK_Up, 0, 0, 0
keybd_event VK_Up, 0, KEYEVENTF_KEYUP, 0
Case ("DOWN")
keybd_event VK_Down, 0, 0, 0
keybd_event VK_Down, 0, KEYEVENTF_KEYUP, 0
Case ("LEFT")
keybd_event VK_Left, 0, 0, 0
keybd_event VK_Left, 0, KEYEVENTF_KEYUP, 0
Case ("RIGHT")
keybd_event VK_Right, 0, 0, 0
keybd_event VK_Right, 0, KEYEVENTF_KEYUP, 0
Case ("OPEN")
keybd_event VK_Return, 0, 0, 0
keybd_event VK_Return, 0, KEYEVENTF_KEYUP, 0
Case ("OK")
keybd_event VK_Return, 0, 0, 0
keybd_event VK_Return, 0, KEYEVENTF_KEYUP, 0
Case ("EXIT")
End
End Select
End Function

Public Sub Start()
keybd_event VK_Control, 0, 0, 0
keybd_event VK_Escape, 0, 0, 0
keybd_event VK_Down, 0, 0, 0
keybd_event VK_Control, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_Escape, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_Down, 0, KEYEVENTF_KEYUP, 0
End Sub
Public Sub Close_window()
keybd_event VK_Alter, 0, 0, 0
keybd_event VK_F4, 0, 0, 0
keybd_event VK_Alter, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_F4, 0, KEYEVENTF_KEYUP, 0
End Sub

Function CMD_List()
Dim TxT As String, Temp As String
Open App.Path & "commands.txt" For Input As #1
Do Until EOF(1)
Line Input #1, TxT
Temp = Left(TxT, 8)
If Temp = "S=" Then
TxT = Mid(TxT, 9, Len(TxT))
List1.AddItem TxT
End If
Loop
Close #1
End Function
Function SelMSG(Msg As String)
Dim Temp As String
Dim i As Integer
For i = 0 To List1.ListCount
Temp = List1.List(i)
If Trim(UCase(Temp)) = Trim(UCase(Msg)) Then
List1.ListIndex = i
Exit Function
End If
Next
End Function

“Command.txt” file

[Grammer]
Type=Cfg
[S]
S=Start
S=Go
S=Up
S=Down
S=Left
S=Right
S=Open
S=Ok
S=Close
S=Exit

Past this “command.txt” file in this program main directory.

Download this Project: www.geocities.com/redu0007

Operation:
Say “Start” then start menu will open, then say “Up” or “Down” it will select a program or say “Left” or “Right”, select your desire program then say “Ok” or “Open”. Enjoy this program.

Conclusion:
I developed this program that published by Computer JAGAT in Bangladesh, May, 2006.

No comments: