使用c#将语音转换为文本 [英] Convert Speech To Text using c#

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

问题描述

我编写了以下代码,使用.NET内置的Speech API执行语音识别,但它无法识别语音。你能帮忙吗?

I have written the following code to perform speech recognition using the Speech API built into .NET, but it's not recognising speech. Could you please help?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech;
using System.Speech.Synthesis;
using System.Speech.Recognition;
using System.Speech.Recognition.SrgsGrammar;
using System.Threading;


namespace SpeechToText
{
    public partial class Form1 : Form
    {
        SpeechSynthesizer sSynth = new SpeechSynthesizer();
        PromptBuilder pBuilder = new PromptBuilder();
        SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();
       
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
          pBuilder.ClearContent();
            pBuilder.AppendText(textBox1.Text);
            sSynth.Speak(pBuilder);
        }

        private void button2_Click(object sender, EventArgs e)
        {
           button2.Enabled = false;
            button3.Enabled= true;
            Choices sList = new Choices();
            sList.Add(new string[] { "hello","hi","how","are","you","srinivas","test","i"});
            Grammar gr = new Grammar(new GrammarBuilder(sList));
            try
            {
                sRecognize.RequestRecognizerUpdate();
                sRecognize.LoadGrammar(gr);
                sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;

                sRecognize.SetInputToDefaultAudioDevice();
                sRecognize.RecognizeAsync(RecognizeMode.Multiple);

            }
            catch
            {
                return;
            }
          /*  sRecognize.SetInputToDefaultAudioDevice();
            sRecognize.LoadGrammar(new DictationGrammar());
            sRecognize.SpeechRecognized += new EventHandler(sRecognize_SpeechRecognized);
            sRecognize.RecognizeAsync(RecognizeMode.Multiple);*/

        }

        void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
           /* foreach (RecognizedWordUnit word in e.Result.Words)
            {
                listBox1.Items.Add(word.Text);
            }*/
            if (e.Result.Text == "exit")
            {
                Application.Exit();
            }
            else
            {
                textBox1.Text = textBox1.Text + " " + e.Result.ToString();
            }
        }

       

        private void Form1_Load(object sender, EventArgs e)
        {
          // sRecognize.SpeechRecognized += new EventHandler(sRecognize_SpeechRecognized);

        }

       
       
    }
}

推荐答案





我从不尝试过,但我认为它会起作用:



一些链接: http://msdn.microsoft.com/en-us/library/hh361683(v = office.14).aspx [ ^ ]

C#Speec h to Text [ ^ ]

演讲C#中的识别,语音到文本,文本到语音和语音合成[ ^ ]
Hi,

I never try it but I think it will work :

Some Links : http://msdn.microsoft.com/en-us/library/hh361683(v=office.14).aspx[^]
C# Speech to Text[^]
Speech recognition, speech to text, text to speech, and speech synthesis in C#[^]


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

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