本例子主要介绍如何用C#开发一个语音阅读文本的例子。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using DotNetSpeech;namespace SpeakDemo{ public partial class Form1 : Form { public Form1() { InitializeComponent(); txtContent.Text = "该例子由Andrew提供,博客:http://www.cnblogs.com/andrew-blog"; } //获取选择的速度 private int GetSpeedSelected() { if (rbtnFast.Checked) { return 2; } if (rbtnNomal.Checked) { return 0; } if (rbtnSlow.Checked) { return -3; } return 0; } //阅读函数 private void Read(string text) { SpVoice sp = new SpVoice(); sp.Rate = GetSpeedSelected(); SpeechVoiceSpeakFlags sFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync; sp.Speak(text, sFlags); } private void btnRead_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtContent.Text)) Read("请输入需要朗读的文本"); else Read(txtContent.Text); } }}
评论