Click here to Skip to main content
15,917,565 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a project in which I want to transcribe my audio files to text form using SAPI.
Audio files are usually in wave format and only contain text content, so it is easy for the engine to recognize that and convert to text.

Pre requested. SAPI Engine should be trained with User voice before recognizing. Please help urgently.

I have got a sample code from another forum but it didn't work out for me. I am not language specific so any language code will be entertained.

VB.NET
Imports System
Imports SpeechLib
Imports System.Speech.Recognition
'Imports AudioUtils;

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 fileDlg As New OpenFileDialog()
        'Dim wave As WaveFile()

        If fileDlg.ShowDialog() = DialogResult.OK Then
            'wave = New WaveFile(fileDlg.FileName)

            TextBox1.Text = "Reading .WAV file..."

            'wave.Read()

            TextBox1.Text = OpenFileDialog1.FileName
            'TextBox1.Text = "Finished Reading .WAV file..."

            'm_DrawWave = True

            Refresh()

        End If

        'Dim dr As DialogResult
        'dr = OpenFileDialog1.ShowDialog()
        'If dr = Windows.Forms.DialogResult.OK Then
        '    If Not OpenFileDialog1.FileName.Contains("D:\\Documents and Settings\\Umaid\\My Documents\\Visual Studio 2008\\Projects\\AudioTest\\AudioTest\\Check1.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() {"Umaid Saleem"}
        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
Posted
Updated 5-Dec-09 16:42pm
v2

Well i agree that I copied this code, but modify it for my own use. I have commented some lines because unable to make a use of it.

I want to clear my question again that I want to take an audio file and convert it to text. Audio file is in wave form only. I just need suggestion or sample program only to grab an idea that how it is processing.

My project is very large, this is only a part of it for that I just only need some help if provided.
 
Share this answer
 
So your attempts at this project amount to copying code and deciding it 'doesn't work' ? Your best bet is it experiment with the code you've found, and if you ask a question, ask something specific, tell us how it 'doesn't work' so we know what you need. Saying 'give me code in any language' is not what these forums are about. We're about helping YOU become a better programmer, not doing free work for you.
 
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