資源簡介
基于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個文件信息
評論
共有 條評論