文字转语音保存音频和在线朗读
生活随笔
收集整理的這篇文章主要介紹了
文字转语音保存音频和在线朗读
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
開發軟件以及運用程序集
VS C# winform
程序集 System.Speech.dll, v4.0.0.0
另作者也是小白,一起多多交流。
代碼如下:
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();}}
總結
以上是生活随笔為你收集整理的文字转语音保存音频和在线朗读的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [AtCoder Educational
- 下一篇: [CodeForces1603D] Ar