Hi there you all,
I need some help with something that sound like an easy task, but in fact could be very very difficult. The problem is as follows:
In my program, I have the following situation:
(My program makes use of Speech Recognition)
A TextBox, named TextBox1, gives the user Text to read.
As the user read the text thru a microphone, the text is displayed in a second TextBox, named TextBox2. (The text that are recognised by the dictation engine when reading the text in TextBox1, are displayed in the TextBox2)
Now, here is where the problem comes in: When the user has finished reading the text in TextBox1, he clicks on a button, named btnResult. The text of TextBox1, must then be compared with the text of TextBox2 and a percentage must be given of how accurate the text compare to each other (of TextBox1 with the text of TextBox2).
Please guys, this is officially a problem that kept me busy for 4 months now. I have tried everything – or almost everything. This is the code that are tried (Thanks to a guy from this site for his help! – Kojiro) – but it still does not work – Any suggestions are welcome, please…The problem with the code below is that I get an Overflow Error Message, although I made sure that there is text in both TextBoxes…
THE CODE:
Private Sub cmdTextStart_Click()
Dim colA As New Collection
Dim colB As New Collection
Dim strA As String
Dim strB As String
Dim Words As Long
Dim Percent As Long
Dim intSpace As Long
Dim intSpaceB As Long
Dim strSentenceA As String
Dim strSentenceB As String
Dim i As Long
strA = Text1.Text
strB = Text2.Text
'assumes that both textboxes have same no. of sentences.
'remove space after period
strA = Replace(strA, ". ", "."
strB = Replace(strB, ". ", "."
strA = UCase(strA) 'uppercase strings
strB = UCase(strB)
Do
intSpace = InStr(1, strA, "."
If intSpace <> 0 Then
strSentenceA = Left(strA, intSpace - 1)
colA.Add strSentenceA
strA = Right(strA, Len(strA) - intSpace)
End If
intSpaceB = InStr(1, strB, "."
If intSpaceB <> 0 Then
strSentenceB = Left(strB, intSpaceB - 1)
colB.Add strSentenceB
strB = Right(strB, Len(strB) - intSpaceB)
End If
Loop While intSpace <> 0
For i = 1 To colA.Count
'MsgBox colA.Item(i) & vbCrLf & colB.Item(i)
Call Compare(colA.Item(i), colB.Item(i), Percent, Words)
Next
Percent = (Percent / Words) * 100 ' and the percentage
MsgBox "The boxes are " & Percent & "% equal to each other", _
vbInformation, "Result..."
End Sub
Sub Compare(strA As String, strB As String, ByRef Percent As Long, ByRef Words As Long)
Dim colA As New Collection
Dim colB As New Collection
Dim intSpace As Integer
Dim intSpaceB As Integer
Dim i As Integer
Dim k As Integer
Dim x As String
Do
intSpace = InStr(1, strA, " "
If intSpace <> 0 Then
colA.Add Left(strA, intSpace - 1)
x = Left(strA, intSpace - 1)
strA = Right(strA, Len(strA) - intSpace)
Else
x = Right(strA, Len(strA) - intSpace)
colA.Add x
End If
Loop While intSpace <> 0
Do
intSpaceB = InStr(1, strB, " "
If intSpaceB <> 0 Then
colB.Add Left(strB, intSpaceB - 1)
strB = Right(strB, Len(strB) - intSpaceB)
Else
x = Right(strB, Len(strB) - intSpaceB)
colB.Add x
End If
Loop While intSpaceB <> 0
'find which sentence is longer.
If colA.Count < colB.Count Then
Words = Words + colB.Count 'word count of sentence having the more words
For i = 1 To colA.Count
For k = 1 To colB.Count
If colA.Item(i) = colB.Item(k) Then
Percent = Percent + 1
colB.Remove (k) 'why? you figure it out.. ;-)
Exit For
End If
Next
Next
Else
Words = Words + colA.Count
For i = 1 To colB.Count
For k = 1 To colA.Count
If colB.Item(i) = colA.Item(k) Then
Percent = Percent + 1
colA.Remove (k) 'why? you figure it out.. ;-)
Exit For
End If
Next
Next
End If
'----- section doesn't work 'faulty err.. bugs' -----
''find which sentence is longer.
'If colA.Count < colB.Count Then
' For i = 1 To colA.Count
' lngSuccess = InStr(1, strTempB, colA.Item(i), vbTextCompare)
' If lngSuccess > 0 Then
' Percent = Percent + 1
' strTempB = Replace(strTempB, colA.Item(i), "", , 1)
' 'MsgBox colA.Item(i) & vbCrLf & strTempB
' End If
' Next
' Words = Words + colB.Count 'word count of sentence having the more words
'Else
' For i = 1 To colB.Count
' lngSuccess = InStr(1, strTempA, colB.Item(i), vbTextCompare)
' If lngSuccess > 0 Then
' Percent = Percent + 1
' strTempA = Replace(strTempA, colB.Item(i), "", , 1)
' End If
' Next
' Words = Words + colA.Count 'word count of sentence having the more words
'End If
End Sub
The reason why I said that the problem is not that easy to solve is because the following things should be kept in mind when coding the problem:
1.) The spaces between words sold be taken in consideration
2.) The TextBoxes could not be compared line by line because the following situation could appear:
TextBox1: (Text that is given to user to read)
Line 1: This is a speech Recognition Test. Please speak in a natural tone of voice.
Line 2: Please do not speak to fast.
TextBox2: (Text that is recognised by Dictation engine)- When an extra word is recognised by dictation engine in Line1 and the words is continued in Line2:
Line 1: This is a speech Recognition Test. Please speak in the a natural tone
Line 2: of voice. Please do not speak to fast.
So as you all could see – the problem has some crazy things to keep in mind – but it is not impossible to solve – somewhere in the world on this great site there must be someone who could solve this stupid problem – please guys – help!
Thank you very much for your time and Effort
Best Regards from South Africa
C-Power
To Be Is To Do And To Do Is To Do Now Because Tomorrow May Not Be
I need some help with something that sound like an easy task, but in fact could be very very difficult. The problem is as follows:
In my program, I have the following situation:
(My program makes use of Speech Recognition)
A TextBox, named TextBox1, gives the user Text to read.
As the user read the text thru a microphone, the text is displayed in a second TextBox, named TextBox2. (The text that are recognised by the dictation engine when reading the text in TextBox1, are displayed in the TextBox2)
Now, here is where the problem comes in: When the user has finished reading the text in TextBox1, he clicks on a button, named btnResult. The text of TextBox1, must then be compared with the text of TextBox2 and a percentage must be given of how accurate the text compare to each other (of TextBox1 with the text of TextBox2).
Please guys, this is officially a problem that kept me busy for 4 months now. I have tried everything – or almost everything. This is the code that are tried (Thanks to a guy from this site for his help! – Kojiro) – but it still does not work – Any suggestions are welcome, please…The problem with the code below is that I get an Overflow Error Message, although I made sure that there is text in both TextBoxes…
THE CODE:
Private Sub cmdTextStart_Click()
Dim colA As New Collection
Dim colB As New Collection
Dim strA As String
Dim strB As String
Dim Words As Long
Dim Percent As Long
Dim intSpace As Long
Dim intSpaceB As Long
Dim strSentenceA As String
Dim strSentenceB As String
Dim i As Long
strA = Text1.Text
strB = Text2.Text
'assumes that both textboxes have same no. of sentences.
'remove space after period
strA = Replace(strA, ". ", "."
strB = Replace(strB, ". ", "."
strA = UCase(strA) 'uppercase strings
strB = UCase(strB)
Do
intSpace = InStr(1, strA, "."
If intSpace <> 0 Then
strSentenceA = Left(strA, intSpace - 1)
colA.Add strSentenceA
strA = Right(strA, Len(strA) - intSpace)
End If
intSpaceB = InStr(1, strB, "."
If intSpaceB <> 0 Then
strSentenceB = Left(strB, intSpaceB - 1)
colB.Add strSentenceB
strB = Right(strB, Len(strB) - intSpaceB)
End If
Loop While intSpace <> 0
For i = 1 To colA.Count
'MsgBox colA.Item(i) & vbCrLf & colB.Item(i)
Call Compare(colA.Item(i), colB.Item(i), Percent, Words)
Next
Percent = (Percent / Words) * 100 ' and the percentage
MsgBox "The boxes are " & Percent & "% equal to each other", _
vbInformation, "Result..."
End Sub
Sub Compare(strA As String, strB As String, ByRef Percent As Long, ByRef Words As Long)
Dim colA As New Collection
Dim colB As New Collection
Dim intSpace As Integer
Dim intSpaceB As Integer
Dim i As Integer
Dim k As Integer
Dim x As String
Do
intSpace = InStr(1, strA, " "
If intSpace <> 0 Then
colA.Add Left(strA, intSpace - 1)
x = Left(strA, intSpace - 1)
strA = Right(strA, Len(strA) - intSpace)
Else
x = Right(strA, Len(strA) - intSpace)
colA.Add x
End If
Loop While intSpace <> 0
Do
intSpaceB = InStr(1, strB, " "
If intSpaceB <> 0 Then
colB.Add Left(strB, intSpaceB - 1)
strB = Right(strB, Len(strB) - intSpaceB)
Else
x = Right(strB, Len(strB) - intSpaceB)
colB.Add x
End If
Loop While intSpaceB <> 0
'find which sentence is longer.
If colA.Count < colB.Count Then
Words = Words + colB.Count 'word count of sentence having the more words
For i = 1 To colA.Count
For k = 1 To colB.Count
If colA.Item(i) = colB.Item(k) Then
Percent = Percent + 1
colB.Remove (k) 'why? you figure it out.. ;-)
Exit For
End If
Next
Next
Else
Words = Words + colA.Count
For i = 1 To colB.Count
For k = 1 To colA.Count
If colB.Item(i) = colA.Item(k) Then
Percent = Percent + 1
colA.Remove (k) 'why? you figure it out.. ;-)
Exit For
End If
Next
Next
End If
'----- section doesn't work 'faulty err.. bugs' -----
''find which sentence is longer.
'If colA.Count < colB.Count Then
' For i = 1 To colA.Count
' lngSuccess = InStr(1, strTempB, colA.Item(i), vbTextCompare)
' If lngSuccess > 0 Then
' Percent = Percent + 1
' strTempB = Replace(strTempB, colA.Item(i), "", , 1)
' 'MsgBox colA.Item(i) & vbCrLf & strTempB
' End If
' Next
' Words = Words + colB.Count 'word count of sentence having the more words
'Else
' For i = 1 To colB.Count
' lngSuccess = InStr(1, strTempA, colB.Item(i), vbTextCompare)
' If lngSuccess > 0 Then
' Percent = Percent + 1
' strTempA = Replace(strTempA, colB.Item(i), "", , 1)
' End If
' Next
' Words = Words + colA.Count 'word count of sentence having the more words
'End If
End Sub
The reason why I said that the problem is not that easy to solve is because the following things should be kept in mind when coding the problem:
1.) The spaces between words sold be taken in consideration
2.) The TextBoxes could not be compared line by line because the following situation could appear:
TextBox1: (Text that is given to user to read)
Line 1: This is a speech Recognition Test. Please speak in a natural tone of voice.
Line 2: Please do not speak to fast.
TextBox2: (Text that is recognised by Dictation engine)- When an extra word is recognised by dictation engine in Line1 and the words is continued in Line2:
Line 1: This is a speech Recognition Test. Please speak in the a natural tone
Line 2: of voice. Please do not speak to fast.
So as you all could see – the problem has some crazy things to keep in mind – but it is not impossible to solve – somewhere in the world on this great site there must be someone who could solve this stupid problem – please guys – help!
Thank you very much for your time and Effort
Best Regards from South Africa
C-Power
To Be Is To Do And To Do Is To Do Now Because Tomorrow May Not Be