前一段时间做过语音识别,因为时间比较紧,所以就在网上找了一些代码用上了,发现些的很复杂,现在想要把语音识别应用到Unity项目中来,所以又梳理了一下发现其实微软已经给我们封装了很好类库。下面是采用的微软的Speech SDK5.1 ,数据库采用的MySQL数据库(MySQL数据库昨天刚刚接触,不过感觉很好使比SQL Server 要好用,速度也不较快,觉得一般的项目的话MySQL就能应付了)
界面可以根据自己的爱好自己设计了 ^_^
下面附上代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//添加数据库引用
using MySQLDriverCS;
using System.Data.Odbc;
//语音转换引用
using DotNetSpeech;
//using SpeechLib;
//添加语音识别引用
using System.Speech.Recognition;
using System.Threading;
namespace SpeechDemo
{
public partial class Form1 : Form
{
//定义语音识别的类
SpeechRecognizer spr;
List<string> li;
public Form1()
{
InitializeComponent();
}
//private SpeechRecognitionEngine spre;
private SpVoice voice;
SpeechVoiceSpeakFlags svsf = SpeechVoiceSpeakFlags.SVSFlagsAsync;
//load加载
private void Form1_Load(object sender, EventArgs e)
{
voice = new DotNetSpeech.SpVoice(); //实例化
this.txt_text.Text = "";
this.cmb_type.Text = "中文";
this.btn_pause.Text = "暂停";
this.voice.Rate = 0;
this.voice.Volume = 50;
li = this.MySQConnectionMother();
this.txt_recive.Focus();
}
//speec