C# 可以通过引用.net framework 框架下的语音播放来实现自己的语音播放。
先来看看简单的效果示例:
上图的主要控件是: TextBox,button .
当我们点击语音朗读按钮,程序将自动朗读(女生朗读)文本框内的内容。
笔者开发平台:Vs2013. 开发语言:C#
下面附上关键源码:
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; ///------一定要加上这个命名空间
namespace Volum
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
///---声明 语音朗读对象
SpeechSynthesizer sps = new SpeechSynthesizer();
///---关闭对话框事件,即 退出按钮事件
private void exitBtn_Click(object sender, EventArgs e)
{
///---释放 SpeechSynthesizer 对象占有的资源
sps.Dispose();
///----退出,关闭对话框
Application.Exit();
}
///---语音朗读按钮事件
private void voiceBtn_Click(object sender, EventArgs e)
{
if (text_Box.Text != "")
{
///---设置语音播放的音量
sps.Volume = 20;
///--设置语音播放速率
sps.Rate = 4;
///---SpeechSynthesizer 获取 text_Box内的文字并进行朗读。
sps.SpeakAsync(text_Box.Text);
}
}
}
}
接着是引用 该语音播放 的步骤&