语音到文本帮助<基本> [英] VOICE TO TEXT Help <basic>

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

问题描述

我需要将语音转换为文本.我已经写了一个代码,可以将文本转换为语音,并且可以正常工作.可以有人将我定向到一个站点,该站点为我提供逐步指导以将语音转换为文本.

我已经搜索并访问了大多数有关语音转换为文本的教程,但没有一个能提供更好的效果答案.

谢谢!

i need to convert voice to text. i have already written a code that could convert text to voice, and it works. can some one direct me to a site that gives me step by step instructions to convert voice to text.

i have googled and visited most of the tutorials on voice to text, but non of them give a better answer.

thank you !

推荐答案

此代码应该可以工作使用Microsoft语音SDK时,它可能与3.5框架中System.Speech程序集的代码相似.

This code should work with the Microsoft Speech SDK, it's probably similar code for the System.Speech assembly in the 3.5 framework.

using System;
using System.Collections.Generic;
using System.IO;
using System.Media;
using System.Text;
using SpeechLib;

namespace YourNameSpace
{
	public class VoiceRecognitionListener
	{

		private SpeechLib.SpSharedRecoContextClass recContext;
		private SpeechLib.ISpRecoGrammar recGrammar;

		public VoiceRecognitionListener()
		{
			/// Create an instance of SpSharedRecoContextClass which will be used
			/// to interface with the incoming audio stream
			recContext = new SpSharedRecoContextClass();

			//Create the grammar object          
			recContext.CreateGrammar(1, out recGrammar);

			//Set appropriate grammar mode
			recGrammar.SetDictationState(SpeechLib.SPRULESTATE.SPRS_ACTIVE);
			recGrammar.SetGrammarState(SPGRAMMARSTATE.SPGS_ENABLED);

			// Setting  this will give you ability retain the wav input
			recContext.RetainedAudio = SpeechRetainedAudioOptions.SRAORetainAudio;

			/// Bind a callback to the recognition event which will be invoked
			/// When a dictated phrase has been recognised.
			recContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(this.handleRecognition);
		}

		/// <summary>
		/// Define a callback that implements interface defined by the  
		/// _ISpeechRecoContextEvents_RecognitionEventHandler delegate in the SpeechLib Library
		/// This will be invoked every time a phrase is recognized. We use this callback to
		/// to keep track of the text dictated so far.
		/// </summary>
		public void handleRecognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
		{
			string text = String.Empty;
			text += Result.PhraseInfo.GetText(0, -1, true);

			//The text variable now contains the spoken words as text, pass it off to whatever part of your program is appropriate, or raise an event with it as an argument etc.

		}

	}
}












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

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