門診叫號系統系列-1.語音叫號 .net c#

 最近收到一個需求,朋友診室須要作到門診叫號,流程以下:病人選擇醫生-刷身份證排隊-醫生點擊病人姓名叫號。測試

通過團隊的努力,一個簡易的門診叫號系統已經完成。如今把各個功能記錄下來,方便之後查看。this

1.語音叫號spa

叫號的DLL:DotNetSpeech.dllorm

測試代碼以下:blog

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;
            }
        }
    }
}

  測試界面以下:string

 

注意事項:採用DotNetSpeech.dll 是不支持64位的,啓動的程序要編譯爲X86,DLL編譯須要ANYCPU,很奇怪,這個找不到緣由it

相關文章
相關標籤/搜索