HI there guys
I urgently need some help with a problem that I think should not be that difficult, but although I have already mentioned this problem on this site – nobody were able to help me. Therefore, I am going to give you a more brief description of what the problem actually is and what I have tried – but did not work. Please guys – I would appreciate it if you could help me with the following:
I developed a speech recognition program, by making use of examples in books and SDK`s of speech recognition software companies. The program that I have developed gives text to the user to read. The text is given in a ListBox, called ListBox1. As the user read the text thru a microphone, the text that is recognized by the dictation engine, is displayed in a second Listbox, called ListBox2. After the user has finished reading the text, he click’s on a button, called btnResult. A percentage is then displayed of how accurate the text of ListBox1 compares to the text of ListBox2.
Now here is my problem:
At first I made use of TextBoxes instead of ListBoxes. (TextBox1 gives the text to be read and TextBox2 display the text that are recognized by the dictation engine). Why I changed to making use of ListBoxes instead of Textboxes is a long story – I am not going to waste your time – just trust me – ListBoxes is more appropriate. I now tried to implement ListBoxes instead of TextBoxes. The problem which I have is as follows:
When the user read the Text of ListBox1 – the text that are displayed in ListBox2 (text that are recognized by dictation engine), are not displayed correctly. For example:
When the following text is given to the user to read:
LISTBOX1
This is a speech Accuracy Test. Please speak in a natural tone of voice.
The text is displayed as follows (in ListbOx):
LISTBOX2
This is a speech Accuracy Test.
Please speak in a natural tone of voice.
As you can see: Instead of continuing the second sentence next to the first,
The ListBox continue the second sentence, below the first. That’s it! That’s my problem.
If there are still space available next to a sentence, then the text that are read, must continue next to that sentence. I have included the code that is triggered when speaking thru the microphone in order to explain where the problem is in the code:
The user clicks on a START button and then begins reading the text of ListBox1:
Private Sub btnStart_Click()
SapiApp.EngineDeactivate
Debug.Assert Not m_bRecoRunning
' 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
Now the following code is triggered when speaking:
' 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
strText = Result.PhraseInfo.GetText
Debug.Print "Recognition: " & strText & ", " & _
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)
End Sub
THE PROBLEM IS ABOVE WITH THE LAST THREE LINES OF CODE – REMMEMBER THAT THIS CODE IS WRITTEN WHEN MAKING USE OF TWO TEXTBOXES INSTEAD OF TWO LISTBOXES:
THESE THREE LINES OF CODE:
txtSpeech.SelStart = m_cChars
txtSpeech.SelText = strText & " "
m_cChars = m_cChars + 1 + Len(strText)
IS WHERE THE PROBLEM IS. A Listbox does not have the functions of SelStart and SelText. Instead of making use of the three lines of code above, I have replaced the three lines of code with:
List2.AddItem strText
With the replacement of the one line of code above, the text are displayed in ListBox2, but the problem that I have mentioned above, occurs. I know something still have to be added to the one line above in order to replace those three lines of code – Could anyone please help me with this?
Thanks guys
Regards
C-Power
I urgently need some help with a problem that I think should not be that difficult, but although I have already mentioned this problem on this site – nobody were able to help me. Therefore, I am going to give you a more brief description of what the problem actually is and what I have tried – but did not work. Please guys – I would appreciate it if you could help me with the following:
I developed a speech recognition program, by making use of examples in books and SDK`s of speech recognition software companies. The program that I have developed gives text to the user to read. The text is given in a ListBox, called ListBox1. As the user read the text thru a microphone, the text that is recognized by the dictation engine, is displayed in a second Listbox, called ListBox2. After the user has finished reading the text, he click’s on a button, called btnResult. A percentage is then displayed of how accurate the text of ListBox1 compares to the text of ListBox2.
Now here is my problem:
At first I made use of TextBoxes instead of ListBoxes. (TextBox1 gives the text to be read and TextBox2 display the text that are recognized by the dictation engine). Why I changed to making use of ListBoxes instead of Textboxes is a long story – I am not going to waste your time – just trust me – ListBoxes is more appropriate. I now tried to implement ListBoxes instead of TextBoxes. The problem which I have is as follows:
When the user read the Text of ListBox1 – the text that are displayed in ListBox2 (text that are recognized by dictation engine), are not displayed correctly. For example:
When the following text is given to the user to read:
LISTBOX1
This is a speech Accuracy Test. Please speak in a natural tone of voice.
The text is displayed as follows (in ListbOx):
LISTBOX2
This is a speech Accuracy Test.
Please speak in a natural tone of voice.
As you can see: Instead of continuing the second sentence next to the first,
The ListBox continue the second sentence, below the first. That’s it! That’s my problem.
If there are still space available next to a sentence, then the text that are read, must continue next to that sentence. I have included the code that is triggered when speaking thru the microphone in order to explain where the problem is in the code:
The user clicks on a START button and then begins reading the text of ListBox1:
Private Sub btnStart_Click()
SapiApp.EngineDeactivate
Debug.Assert Not m_bRecoRunning
' 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
Now the following code is triggered when speaking:
' 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
strText = Result.PhraseInfo.GetText
Debug.Print "Recognition: " & strText & ", " & _
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)
End Sub
THE PROBLEM IS ABOVE WITH THE LAST THREE LINES OF CODE – REMMEMBER THAT THIS CODE IS WRITTEN WHEN MAKING USE OF TWO TEXTBOXES INSTEAD OF TWO LISTBOXES:
THESE THREE LINES OF CODE:
txtSpeech.SelStart = m_cChars
txtSpeech.SelText = strText & " "
m_cChars = m_cChars + 1 + Len(strText)
IS WHERE THE PROBLEM IS. A Listbox does not have the functions of SelStart and SelText. Instead of making use of the three lines of code above, I have replaced the three lines of code with:
List2.AddItem strText
With the replacement of the one line of code above, the text are displayed in ListBox2, but the problem that I have mentioned above, occurs. I know something still have to be added to the one line above in order to replace those three lines of code – Could anyone please help me with this?
Thanks guys
Regards
C-Power