c#语音报读

来源:互联网 发布:手机端口查询 编辑:程序博客网 时间:2024/05/21 08:00

最近在写程序的时候用到了语音报读的模块,在c++中使用TTS可以实现,但是有点麻烦,在使用c#时,发现直接添加引用就可以了。

1.添加引用,如下图所示:






2.在程序中添加 引用:



3.在窗体初始化的同时,另开一个线程异步报读文本:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Speech.Synthesis;using System.Threading;using System.IO;using System.Diagnostics;namespace ScannerGun{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();            Thread thread = new Thread(Voice);            thread.IsBackground = true;            thread.Start();        }        public void Voice()        {            SpeechSynthesizer speech = new SpeechSynthesizer();            speech.Speak("即将进行扫描枪的测试,请根据页面提示进行扫描,然后检测扫描结果是否正确,正确则点击测试成功按钮,错误则点击测试失败按钮");        }    }}


原创粉丝点击