本帖最后由 liu8359 于 2021-6-24 10:10 编辑
VS C# winform
程序集 System.Speech.dll, v4.0.0.0
[C#] 纯文本查看 复制代码
public partial class Form1 : Form
{
private SpeechSynthesizer speech;
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
speech= new SpeechSynthesizer();
}
/// <summary>
/// 读
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonRead_Click(object sender, EventArgs e)
{
var rate = trackBarSpeed.Value;//语速
var volume = trackBarVolumn.Value;//音量大小
var text = textMsg.Text;//读取文字
//开启线程
Task.Run(() =>
{
speech.Rate = rate;
speech.Volume = volume;
speech.Speak(text);
});
}
/// <summary>
/// 暂停
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonPause_Click(object sender, EventArgs e)
{
speech.Pause();
}
/// <summary>
/// 继续
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonContinue_Click(object sender, EventArgs e)
{
speech.Resume();
}
/// <summary>
/// 录音
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonRecord_Click(object sender, EventArgs e)
{
var rate = trackBarSpeed.Value;//语速
var volume = trackBarVolumn.Value;//音量大小
var text = textMsg.Text;//读取文字
SpeechSynthesizer speech= new SpeechSynthesizer();
speech.Rate = rate;
speech.Volume = volume;
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Wave Files|*.wav";
string Str= text.Substring(0,6);
sfd.FileName = Str + "录音文件-作者QQ673071996.wav";
speech.SetOutputToWaveFile(sfd.FileName);
speech.Speak(textMsg.Text);
speech.SetOutputToDefaultAudioDevice();
MessageBox.Show("完成录音~~", "提示");
}
/// <summary>
/// 关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
蓝奏云:https://wwi.lanzoui.com/iiYv0gg2xvi |