码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2020-04-21 12:37:43      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:attribute   orm   音量   增加   dex   Speak   ++   mic   tostring   

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

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

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,很奇怪,这个找不到原因

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

标签:attribute   orm   音量   增加   dex   Speak   ++   mic   tostring   

原文地址:https://www.cnblogs.com/80028366local/p/12680730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!