将文件转换为文本转换器 [英] Wave file to text convertor

查看:77
本文介绍了将文件转换为文本转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,我想使用SAPI将音频文件转录为文本格式.
音频文件通常为wave格式,并且仅包含文本内容,因此引擎很容易识别出该内容并将其转换为文本.

预先要求.在识别之前,应该使用用户语音对SAPI Engine进行培训.请紧急帮助.

我从另一个论坛上获得了示例代码,但对我来说不起作用.我的语言不是特定语言,因此可以接受任何语言代码.

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.

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

推荐答案

好吧,我同意我复制了这段代码,但是修改了一下以供自己使用.我评论了一些行,因为无法使用它.

我想再次清除我要提取音频文件并将其转换为文本的问题.音频文件仅是波形形式.我只需要建议或示例程序即可了解它的处理方式.

我的项目非常大,这只是其中的一部分,因为我只需要提供一些帮助即可.
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.


所以您在此项目中所做的尝试等同于复制代码并确定它''不起作用吗?最好的选择是尝试使用找到的代码,如果您提出问题,请提出一些具体问题,告诉我们它不起作用"的方式,这样我们就知道您需要什么.说用任何语言给我代码"并不是这些论坛的目的.我们是在帮助您成为一个更好的程序员,而不是为您做自由工作.
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.


这篇关于将文件转换为文本转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆