?
Solved

One Question

Posted on 2003-03-28
5
Medium Priority
?
207 Views
Last Modified: 2010-04-07
I am making a speech recognition program in Visual Basic 6.0, and since I am a beginner, I completely messed up a certain part of the code that is in a module. I am wondering if anyone could help me fix this code up, so I can get my program to work. DICTIONARY.txt is a dictionary saved as a text file in which every single line is another word. I have more code in the form of my program, but this is where my problem is. I want my program to be able to type in a textbox called Form1.T1.Text what you say when you say it into a microphone. Here is the code that is in a module, and thanks in advanced!

Option Explicit

Function LoadVoiceCommands(lstBox As Control) As Boolean

On Local Error GoTo LoadVoiceCommandsError

Dim sNam As String
Dim FileFree As Integer

FileFree = FreeFile

'Check for voice commands text file...
If Dir$(App.Path & "\DICTONARY.Txt") = "" Then
    Exit Function
End If
Dim fnum
Dim Counter
Dim words
'Find next free file
fnum = FreeFile

Counter = 0

Open App.Path & "DICTIONARY.txt" For Input As #fnum
While Not EOF(fnum)
  Input #fnum, words, Counter
  Counter = Counter + 1
Wend
Close #fnum

LoadVoiceCommands = True
Exit Function



LoadVoiceCommandsError:
    Exit Function
End Function

Function ExecuteVoiceCommand(Who As Form, sPhrase As String) As Boolean
On Local Error GoTo ExecuteVoiceCommandError
Select Case LCase$(sPhrase)

Dim X

'Carry out command...

Case "test"
Form1.T1.Text = "test"
       
Case "exit"
End

Case "read"
Form1.Talk1.Speak Form1.T1.Text
Form1.Talk1.Resume

Case "pause"
Form1.Talk1.Pause

Case "off"
Call Form1.VR.Deactivate

Case "save"
Form1.CommonDialog1.CancelError = True
On Error GoTo Errhandler
Form1.Save_DriveA

Case "print"
Form1.CommonDialog1.CancelError = True
On Error GoTo Errhandler
Form1.CommonDialog1.ShowPrinter
Printer.Print "Ultra Speak 2.0"
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print Form1.T1.Text
Case "open"
Form1.CommonDialog1.CancelError = True
On Error GoTo Errhandler 'You must know the file extensions for the open types'
Form1.CommonDialog1.Filter = "All Files (*)|*|" & _
"Text Files (*.txt)|*.txt|" & _
"Rich Text Format (*.rtf)|*.rtf|"
Form1.CommonDialog1.FilterIndex = 1 'The filter determines which type of files can be viewed, some types can't be viewed without calling dll's, etc'
Form1.CommonDialog1.ShowOpen
Form1.T1.Text = Form1.CommonDialog1.FileName
Open Form1.T1.Text For Input As #1
Form1.T1.Text = Input(LOF(1), 1)
Close #1
Errhandler:
End Select
End Function
0
Comment
Question by:Magic09
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 6

Expert Comment

by:rjdown
ID: 8225624
one thing i noticed...

'Input #fnum, words, Counter'

 should read

Input #fnum, words(Counter)

and also words should be declared like this:

Dim Words(10000) As String

where 10000 should be changed to suit number of words in your dictionary.


As for the question...

I'm guessing that somewhere you have a routine that matches the spoken word to an entry to your *words*, but with out seeing more of your code, I'm a bit lost :(

This routine should return an integer value which represents the location of the word within the Words() array. (I will call this value WordsIndex)

You can then simply use

Form.T1.Text = Words(WordsIndex)

Hope that helps....Good luck :)
0
 
LVL 6

Expert Comment

by:rjdown
ID: 8225656
Oh btw just in case you don't know, an array starts at 0, so declaring the Words() array as (10000) will actaully mean it has 10001 entries (0 - 10000)

This is why in that Open->Close section (which seems to be from an answer I gave on a previous question lol), Counter starts at 0, not 1
0
 

Author Comment

by:Magic09
ID: 8226328
Here is the rest of my code... But if I did a routine, wouldn't I have to write a routine for every word in the dictionary?

Dim a As Boolean
Dim b As Integer
Dim c As Integer
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComCtlLib.Button)
    On Error Resume Next
    Select Case Button.Key
        Case "New"
            'ToDo: Add 'New' button code.
            MsgBox "Add 'New' button code."
        Case "Open"
            'ToDo: Add 'Open' button code.
            MsgBox "Add 'Open' button code."
        Case "Save"
            'ToDo: Add 'Save' button code.
            MsgBox "Add 'Save' button code."
        Case "Print"
            'ToDo: Add 'Print' button code.
            MsgBox "Add 'Print' button code."
        Case "Undo"
            'ToDo: Add 'Undo' button code.
            MsgBox "Add 'Undo' button code."
        Case "Copy"
            'ToDo: Add 'Copy' button code.
            MsgBox "Add 'Copy' button code."
        Case "Cut"
            'ToDo: Add 'Cut' button code.
            MsgBox "Add 'Cut' button code."
        Case "Paste"
            'ToDo: Add 'Paste' button code.
            MsgBox "Add 'Paste' button code."
        Case "Bold"
            'ToDo: Add 'Bold' button code.
            MsgBox "Add 'Bold' button code."
        Case "Italic"
            'ToDo: Add 'Italic' button code.
            MsgBox "Add 'Italic' button code."
        Case "Strike Through"
            'ToDo: Add 'Strike Through' button code.
            MsgBox "Add 'Strike Through' button code."
        Case "Underline"
            'ToDo: Add 'Underline' button code.
            MsgBox "Add 'Underline' button code."
    End Select
End Sub




Private Sub Command1_Click()
Call VR.Deactivate
End Sub

Private Sub Command2_Click()
Save_DriveA
End Sub

Public Sub Command3_Click()
CommonDialog1.CancelError = True
On Error GoTo Errhandler 'You must know the file extensions for the open types'
CommonDialog1.Filter = "All Files (*)|*|" & _
"Text Files (*.txt)|*.txt|" & _
"Rich Text Format (*.rtf)|*.rtf|"
CommonDialog1.FilterIndex = 1 'The filter determines which type of files can be viewed, some types can't be viewed without calling dll's, etc'
CommonDialog1.ShowOpen
StrFileName = CommonDialog1.FileName
Open StrFileName For Input As #1
T1.Text = Input(LOF(1), 1)
Close #1
Exit Sub
Errhandler:
End Sub

Private Sub Command4_Click()
Call VR.GrammarFromFile(App.Path & "\Commands.Txt")
Call VR.Activate
End Sub

Private Sub Command5_Click()
Form1.CommonDialog1.CancelError = True
On Error GoTo Errhandler
CommonDialog1.ShowPrinter
Printer.Print "Ultra Speak 2.0"
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print T1.Text
Errhandler:
End Sub

Private Sub Command6_Click()
Talk1.Speak T1.Text
Talk1.Resume
End Sub

Private Sub Command7_Click()
Unload Form1
End Sub

Private Sub Command8_Click()
Talk1.Pause
End Sub

Private Sub Command9_Click()
End
End Sub

Private Sub Form_Load()
Dim M1
Dim WordsIndex As Integer
Dim Words(349899) As String
On Local Error Resume Next

'Load the voice commands from the commands text file...
Call LoadVoiceCommands(lstCommands)

'Setup the voice recognition control...
Call VR.Deactivate
Call VR.GrammarFromFile(App.Path & "\DICTIONARY.Txt")
Call VR.Activate
T1.Text = Words(WordsIndex)
End Sub

Private Sub StatusBar1_PanelClick(ByVal Panel As MSComCtlLib.Panel)

End Sub

Private Sub Label2_Click()
End
End Sub

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

On Local Error Resume Next

'Check to see if we have a matching word...
If Trim$(Phrase) <> "" Then
    Me.Caption = Phrase
    Call ExecuteVoiceCommand(Me, Phrase)
Else
    Me.Caption = "Unrecognized Command..."
End If

End Sub

Private Sub Image5_Click()
Me.WindowState = 1
End Sub


Private Sub DirectSR1_ClickIn(ByVal X As Long, ByVal y As Long)

End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, y As Single)
If Button = vbRightButton Then
Else
a = True
b = X
c = y
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, y As Single)
a = False
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, y As Single)
If a Then
Me.Move (Me.Left + X - b), (Me.Top + y - c)
End If
End Sub
Private Sub Dm_MouseMove(Button As Integer, Shift As Integer, X As Single, y As Single)
If a Then Me.Move (Me.Left + X - b), (Me.Top + y - c)
End Sub
Private Sub Dm_MouseUp(Button As Integer, Shift As Integer, X As Single, y As Single)
a = False
End Sub

Function Save_DriveA()
    Dim X As Integer
                CommonDialog1.CancelError = True
                On Error GoTo Errhandler
    Do
        CommonDialog1.Action = 2    'save file
   

            Exit Do
        DoEvents
    Loop

    X = FreeFile
    Open CommonDialog1.FileName For Output As #X
        Print #X, T1.Text
    Close #X
    MsgBox "Your file has been saved."
Errhandler:
End
End Function

Function Print_T1()
    Dim Z As Integer

    Do
        CommonDialog1.Action = 5    'save file

            Exit Do
        DoEvents
    Loop
        Print "T1.Text"
    Close #X
    MsgBox "Printing..."
End Function

0
 
LVL 6

Accepted Solution

by:
rjdown earned 300 total points
ID: 8227187
Ah um..

looks like your "Phrase" is what is used to identify the word spoken..although I can't seem to find where this value is determined.

However, in answer to your question, in this part of code:

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

On Local Error Resume Next

'Check to see if we have a matching word...
If Trim$(Phrase) <> "" Then
   Me.Caption = Phrase
   Call ExecuteVoiceCommand(Me, Phrase)
Else
   Me.Caption = "Unrecognized Command..."
End If

End Sub
--------------------------------

you could change

Me.Caption = Phrase

to

Form.T1.Text = Phrase


I hope this is what you need :)


PS Also I would advise you to rename your command buttons (Command1, Command2 etc) to something a bit more informative, like cmdSave, cmdPause, cmdQuit etc

0
 

Author Comment

by:Magic09
ID: 8227334
He solves the problem once again! Rofl :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question