• 大小: 151KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: C#
  • 标签: C#  SAPI  语音交互  

资源简介

基于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个文件信息

评论

共有 条评论