资源简介
基于C# 编程,使用微软SAPI SDK的人机交互的语音对话DEMO 展示SAPI的基本用法,便于用户在开发相应的产品时,做一个参考。
代码片段和文件信息
using System;
using System.Windows.Forms;
using System.Globalization;
using System.IO;
using System.Speech.Recognition;
using System.Speech.Synthesis;
namespace Voice_Conversation
{
public partial class Voice_Conversation : Form
{
SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
SpeechSynthesizer Robot = new SpeechSynthesizer();
public Voice_Conversation()
{
InitializeComponent();
this.Load += Voice_Conversation_Load;
}
private void Voice_Conversation_Load(object sender EventArgs e)
{
CultureInfo myCIintl = new CultureInfo(“zh-CN“);
foreach (RecognizerInfo config in SpeechRecognitionEngine.InstalledRecognizers())
{
if (config.Culture.Equals(myCIintl) && config.Id == “MS-2052-80-DESK“)
{
_recognizer = new SpeechRecognitionEngine(config);
break;
}
}
_recognizer.SetInputToDefaultAudioDevice();
_recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(Application.StartupPath + “\\command.txt“)))));
_recognizer.SpeechRecognized += new EventHandler(_recognizer_SpeechRecognized);
_recognizer.RecognizeAsync(RecognizeMode.Multiple);
}
void _recognizer_SpeechRecognized(object sender SpeechRecognizedEventArgs e)
{
string speech = e.Result.Text;
switch (speech)
{
case “你好“:
Robot.Speak(“你好“);
break;
case “今天星期几“:
Robot.Speak(“今天“ + DateTime.Today.ToString(“dddd“));
break;
case “今天几号“:
Robot.Speak(“今天是“ + DateTime.Today.ToString(“yyyy-MM-dd“));
break;
case “现在几点“:
DateTime now = DateTime.Now;
string time = now.GetDateTimeFormats(‘t‘)[0];
Robot.Speak(time);
break;
case “自我介绍一下“:
string path = Application.StartupPath + “/Audio file/Self-introduction.wav“;//.wav音频文件路径
System.Media.SoundPlayer player = new System.Media.SoundPlayer(path);
player.Play();//简单播放一遍
//player.PlayLooping();//循环播放
//player.PlaySync();//另起线程播放
break;
}
}
private void listBox1_SelectedIndexChanged(object sender EventArgs e)
{
}
private void Exit_Click(object sender EventArgs e)
{
this.Close();
this.Dispose();
Application.Exit();
}
private void label1_Click(object sender EventArgs e)
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 54272 2017-01-12 16:47 语音识别\Voice_Conversation\.vs\Voice_Conversation\v14\.suo
文件 189 2016-05-10 13:00 语音识别\Voice_Conversation\Voice_Conversation\App.config
文件 77 2016-05-10 13:43 语音识别\Voice_Conversation\Voice_Conversation\bin\Debug\Audio file\Readme.txt
文件 64 2016-05-10 15:17 语音识别\Voice_Conversation\Voice_Conversation\bin\Debug\command.txt
文件 28672 2017-01-05 13:16 语音识别\Voice_Conversation\Voice_Conversation\bin\Debug\Voice_Conversation.exe
文件 189 2016-05-10 13:00 语音识别\Voice_Conversation\Voice_Conversation\bin\Debug\Voice_Conversation.exe.config
文件 26112 2017-01-05 13:16 语音识别\Voice_Conversation\Voice_Conversation\bin\Debug\Voice_Conversation.pdb
文件 22696 2017-01-12 09:21 语音识别\Voice_Conversation\Voice_Conversation\bin\Debug\Voice_Conversation.vshost.exe
文件 189 2016-05-10 13:00 语音识别\Voice_Conversation\Voice_Conversation\bin\Debug\Voice_Conversation.vshost.exe.config
文件 490 2016-07-16 19:44 语音识别\Voice_Conversation\Voice_Conversation\bin\Debug\Voice_Conversation.vshost.exe.manifest
文件 3120 2016-05-10 15:07 语音识别\Voice_Conversation\Voice_Conversation\Form1.cs
文件 4071 2016-05-10 15:07 语音识别\Voice_Conversation\Voice_Conversation\Form1.Designer.cs
文件 31555 2016-05-10 15:07 语音识别\Voice_Conversation\Voice_Conversation\Form1.resx
文件 1464 2016-05-10 13:59 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 7511 2017-01-05 13:39 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 1354 2016-05-10 13:50 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\Guiding Robot.csproj.FileListAbsolute.txt
文件 1012 2016-05-10 13:49 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\Guiding Robot.csproj.GenerateResource.Cache
文件 2534 2016-05-10 13:47 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\Guiding Robot.csprojResolveAssemblyReference.cache
文件 165376 2017-01-05 13:16 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\Interop.SpeechLib.dll
文件 0 2016-05-10 13:00 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2016-05-10 13:00 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
文件 0 2016-05-10 13:00 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
文件 5170 2017-01-12 09:21 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\Voice_Conversation.csproj.FileListAbsolute.txt
文件 1012 2017-01-05 13:14 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\Voice_Conversation.csproj.GenerateResource.Cache
文件 783 2017-01-05 13:16 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\Voice_Conversation.csproj.ResolveComReference.cache
文件 2534 2016-05-10 13:27 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\Voice_Conversation.csprojResolveAssemblyReference.cache
文件 28672 2017-01-05 13:16 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\Voice_Conversation.exe
文件 17524 2016-05-10 13:49 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\Voice_Conversation.Guiding_Robot.resources
文件 26112 2017-01-05 13:16 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\Voice_Conversation.pdb
文件 180 2017-01-05 13:16 语音识别\Voice_Conversation\Voice_Conversation\obj\Debug\Voice_Conversation.Properties.Resources.resources
............此处省略28个文件信息
相关资源
- C#图书管理系统(功能齐全,包括借还
- C#对TXT读写
- c#仓库信息管理系统
- 用于验证码图片识别的类C#源码
- 一个用WPF编写的串口助手
- WinformC# 模拟登陆百度 HttpWebRequest的应
- c#背单词程序源代码,非常简单
- asp.net实现文件夹上传、修改、删除,
- C#调用photoshop工具源码
- C#串口调试工具44664
- ArcGIS+Engine+C#开发源代码以及图表统计
- C#实现后门程序的
- C#制作的个人存款业务处理程序
- C# WPF+MVVM+EF+多语言
- LitJson.dll C# 与 unity 可用的Json处理插
- C#项目开发案例全程实录第2版光盘
- C#CircularProgressBar
- C# 图书系统 SQL
- 使用鼠标钩子实现透明窗体桌面画图
- 计算两个日期之间工作日天数(c#实现
- c#调用 windows api实现WinForm中嵌入EXE程
- c#吃金豆游戏源代码
- C# 编写的数字式电子时钟控件,颜色
-
C#+xm
l通讯录 - c# / VB 调用refprop.dll
- C#+sqlite 登录Demo
- 手表类C#语言编程实现计算几天后的日
- 小景点售票系统.。。。。C#语言及有
- C# 高德地图百度地图计算两点坐标距
- c#小游戏21点代码和界面
评论
共有 条评论