DotNetSpeech门诊叫号系统系列-1.语音叫号 .net c#

最近收到一个需求,朋友诊室需要做到门诊叫号,流程如下:病人选择医生-刷身份证排队-医生点击病人姓名叫号。

经过团队的努力,一个简易的门诊叫号系统已经完成。现在把各个功能记录下来,方便以后查看。

1.语音叫号

叫号的DLL:DotNetSpeech.dll

测试代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
 
using DotNetSpeech;
 
namespace voice
{
     public partial class Form1 : Form
     {
         public Form1()
         {
             InitializeComponent();
         }
         /// <summary>
         /// 语音列表
         /// </summary>
         List<SpVoice> _voice = new List<SpVoice>();
         private void btnSound_Click( object sender, EventArgs e)
         {           
             this .AddVoice(txtVoice1.Text, int .Parse(txtVolume1.Text), int .Parse(txtRate1.Text));
             this .AddVoice(txtVoice2.Text, int .Parse(txtVolume2.Text), int .Parse(txtRate2.Text));
             for ( int i = 0; i < _voice.Count(); i++)
             {
                 try
                 {
                     //根据文本叫号
                     _voice[i].Speak( this .txtVoiceText.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync);
                 }
                 catch (Exception ex)
                 {
                     txtError.Text = DateTime.Now.ToString() + ex.ToString() + " " + txtError.Text;
                 }
             }
         }
 
         /// <summary>
         /// 增加语音库
         /// </summary>
         /// <param name="p_Name">语音库名称</param>
         /// <param name="p_Volume">音量</param>
         /// <param name="p_Rate">音速</param>
         public void AddVoice( string p_Name, int ? p_Volume, int ? p_Rate)
         {
             try
             {
                 for ( int i = 0; i < _voice.Count(); i++)
                 {
                     if (_voice[i].Voice.GetAttribute( "name" ) == p_Name)
                     {
                         _voice[i].Rate = p_Rate == null ? -3 : p_Rate.Value;
                         if (p_Volume != null ) _voice[i].Volume = p_Volume.Value;
                         return ;
                     }
                 }
                 SpVoice voice = new SpVoice();
                 voice.Voice = voice.GetVoices( string .Format( "name={0}" , p_Name), "" ).Item(0);
                 voice.Rate = p_Rate == null ? -3 : p_Rate.Value;
                 if (p_Volume != null ) voice.Volume = p_Volume.Value;
                 _voice.Add(voice);
             }
             catch (Exception ex) {
                 txtError.Text = DateTime.Now.ToString()+ex.ToString() + " " + txtError.Text;
             }
         }
     }
}

测试界面如下:

注意事项:采用DotNetSpeech.dll 是不支持64位的,启动的程序要编译为X86,DLL编译需要ANYCPU,很奇怪,这个找不到原因

猜你喜欢

转载自www.cnblogs.com/80028366local/p/12680730.html