Click here to Skip to main content
15,889,571 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
In my application i am converting audio (wav file) to text format. I recorded the wav file in microsoft voice only. It is working. But the speech recognition does not work properly. Please help me to rectify the problem. I attached my code with it.

Thanks in advance.
VB
Imports System
Imports System.Speech.Recognition

Public Class Form1

    Dim WithEvents sre As SpeechRecognitionEngine

    Private Sub btnLiterate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLiterate.Click
        If TextBox1.Text.Trim.Length = 0 Then Exit Sub
        sre.SetInputToWaveFile(TextBox1.Text)
        Dim r As RecognitionResult
        r = sre.Recognize()
        If r Is Nothing Then
            TextBox2.Text = "Could not fetch result"
            Return
        End If
        TextBox2.Text = r.Text
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = String.Empty
        Dim dr As DialogResult
        dr = OpenFileDialog1.ShowDialog()
        If dr = Windows.Forms.DialogResult.OK Then
            If Not OpenFileDialog1.FileName.Contains("wav") Then
                MessageBox.Show("Incorrect file")
            Else
                TextBox1.Text = OpenFileDialog1.FileName
            End If
        End If
    End Sub

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        sre = New SpeechRecognitionEngine()

    End Sub

    Private Sub sre_LoadGrammarCompleted(ByVal sender As Object, ByVal e As System.Speech.Recognition.LoadGrammarCompletedEventArgs) Handles sre.LoadGrammarCompleted

    End Sub

    Private Sub sre_SpeechHypothesized(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechHypothesizedEventArgs) Handles sre.SpeechHypothesized
        System.Diagnostics.Debug.Print(e.Result.Text)
    End Sub

    Private Sub sre_SpeechRecognitionRejected(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechRecognitionRejectedEventArgs) Handles sre.SpeechRecognitionRejected
        System.Diagnostics.Debug.Print("Rejected: " & e.Result.Text)
    End Sub

    Private Sub sre_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles sre.SpeechRecognized
        System.Diagnostics.Debug.Print(e.Result.Text)
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim words As String() = New String() {"triskaidekaphobia"}
        Dim c As New Choices(words)
        Dim grmb As New GrammarBuilder(c)
        Dim grm As Grammar = New Grammar(grmb)
        sre.LoadGrammar(grm)
    End Sub

End Class


[edit]Subject and Tags only - OriginalGriff[/edit]
Posted
Updated 7-Feb-12 6:09am
v3
Comments
OriginalGriff 4-Feb-12 3:59am    
"not working properly" is not a useful description - it covers far to much possible failure, form a word being misrecognised, to your PC exploding and the shrapnel amputating your left leg. We can't tell.

Use the "Improve question" widget to edit your question and provide better information.
psgviscom 4-Feb-12 11:32am    
It is not recognizing the voice, instead it displays the message as "could not fetch the result".
OriginalGriff 4-Feb-12 11:50am    
Have you loaded a Grammar?
Set a culture?
Looked at the example? http://msdn.microsoft.com/en-us/library/ms554580.aspx
psgviscom 4-Feb-12 11:54am    
What is the purpose of creating grammer
Christian Graus 5-Feb-12 8:09am    
Surely it tells it the rules to use in recognition ? Why don't you follow the example first, then ask if it does not work ?

1 solution

Based on your variable names, this is not yet a serious project. Have you downloaded samples from MS and run them ? I'd take a sample and progressively change it to be what you want, and test with each change, at this point, as you've been chasing this for days. Is it possible it just can't recognise your voice ? Have you tried more than one input voice ? Have you tried different recordings of different statements ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900