将语音转换为文本 [英] Convert Speech to text

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

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Speech; 
using System.Threading;
using  System.Speech.Recognition ;
using  System.Speech.Synthesis ;    
using  System.Globalization;
using System.IO;
using System.Text; 


namespace testcode
{
    public partial class Read : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {


            SpeechRecognitionEngine RecognitionEngine; 
            using (RecognitionEngine = new SpeechRecognitionEngine(new CultureInfo("en-US")))
            {
                RecognitionEngine.SetInputToWaveFile(Server.MapPath("~/speech.wav"));
                RecognitionEngine.LoadGrammar(new DictationGrammar());
                RecognitionResult Result = RecognitionEngine.Recognize();
                
                StringBuilder Output = new StringBuilder(); 
                foreach (RecognizedWordUnit Word in Result.Words) 
                {
                    Output.Append(Word.Text + " ");
                    textBox1.Text = Output.ToString();
                }
               
            }
            

    }
    }
}


我曾尝试使用此代码将语音转换为文本,但是在必须读取我在
上录制的录音的地方,它一直给我带来错误


i have tried converting voice to text using this code but it keeps on giving me error where it have to read the recording i have recorded on the

RecognitionEngine.SetInputToWaveFile(Server.MapPath("~/speech.wav"));


错误是这样,系统无效操作异常.它无法读取文件


The error is this, system invalide operation exception. it cant read the file

推荐答案

Button1_Click中的代码在服务器端执行!您确定文件位于服务器上的该位置(!),并且可供IIS用户访问吗?
The code in Button1_Click is executed on the server side! Are you sure that the file exists on that place on the server (!) and is accessible for the IIS user?


此错误主要是在应用程序无法映射路径时发生的.因此,请确保该文件的路径正确且文件存在于此.
This error comes mostly when application Failed to map the path. So make yourpath of that file is correct and file exists there.


将wav文件复制到您的项目中并提供完整路径(您可以通过将wav文件拖到您的应用程序中来做到)

RecognitionEngine.SetInputToWaveFile(Server.MapPath(〜/speech.wav"));

替换为

RecognitionEngine.SetInputToWaveFile( @"C:\ Desktop \ IT \ SpeechText90 \ 8mm-devil.wav" );

希望这会有所帮助.
快乐编码:)
Copy the wav file into your project and give full path(You can do it by dragging the wav file into your application)

RecognitionEngine.SetInputToWaveFile(Server.MapPath("~/speech.wav"));

Replace with

RecognitionEngine.SetInputToWaveFile(@"C:\Desktop\IT\SpeechText90\8mm-devil.wav");

Hope this helps.
Happy Coding :)


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

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