
前一段时间做过语音识别,因为时间比较紧,所以就在网上找了一些代码用上了,发现些的很复杂,现在想要把语音识别应用到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();
}
//speech
private void btn_speech_Click(object sender, EventArgs e)
{
voice.Speak(this.txt_text.Text, svsf);
//定义一个线程 并给线程绑定方法
}
public void btnclick()
{
voice.Speak(this.txt_text.Text, svsf);
}
//清空
private void btn_clear_Click(object sender, EventArgs e)
{
this.txt_text.Text = "";
this.btn_pause.Text = "暂停";
}

本文介绍了如何利用微软的Speech SDK5.1 在Unity项目中实现文本转语音(TTS)和语音识别功能。通过连接MySQL数据库,实现了语音交互并提供了简单的用户界面。代码示例包括语音识别引擎的加载、语音暂停与继续、生成语音文件等功能。
最低0.47元/天 解锁文章
2343

被折叠的 条评论
为什么被折叠?



