教你如何用C#制作文字轉(zhuǎn)換成聲音程序
教你如何用C#制作文字轉(zhuǎn)換成聲音程序
在System.Speech命名空間下,SpeechSynthesizer類可以把文字讀出來,一起來玩下~~
首先在Windows窗體項目中引入System.Speech。界面部分:

后臺代碼也很簡單,只不過調(diào)用了SpeechSynthesizer類的一些方法:
using System.Windows.Forms;
using System.Speech;
using System.Speech.Synthesis;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private SpeechSynthesizer ss;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ss = new SpeechSynthesizer();
}
private void buttonRead_Click(object sender, EventArgs e)
{
ss.Rate = trackBarSpeed.Value;
ss.Volume = trackBarVolumn.Value;
ss.SpeakAsync(txtMsg.Text);
}
private void buttonPause_Click(object sender, EventArgs e)
{
ss.Pause();
}
private void buttonContinue_Click(object sender, EventArgs e)
{
ss.Resume();
}
private void buttonRecord_Click(object sender, EventArgs e)
{
SpeechSynthesizer ss = new SpeechSynthesizer();
ss.Rate = trackBarSpeed.Value;
ss.Volume = trackBarVolumn.Value;
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Wave Files|*.wav";
ss.SetOutputToWaveFile(sfd.FileName);
ss.Speak(txtMsg.Text);
ss.SetOutputToDefaultAudioDevice();
MessageBox.Show("完成錄音~~","提示");
}
private void buttonClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
- c# 播放聲音的四種方法
- C#實現(xiàn)用于操作wav聲音文件的類實例
- C#實現(xiàn)通過winmm.dll控制聲音播放的方法
- C# winform中窗口關(guān)閉按鈕的隱藏與禁用詳解
- C# WinForm-Timer控件的使用
- C#用Topshelf創(chuàng)建Windows服務(wù)的步驟分享
- C# Winform中如何繪制動畫示例詳解
- C# Winform調(diào)用百度接口實現(xiàn)人臉識別教程(附源碼)
- C# Winform程序?qū)崿F(xiàn)防止多開的方法總結(jié)【親測】
- C#調(diào)用Win32的API函數(shù)--User32.dll
- C# Winfrom實現(xiàn)Skyline畫直線功能的示例代碼
- c# 通過WinAPI播放PCM聲音
相關(guān)文章
c#中directory 和directoryinfo的使用小結(jié)
當使用C#處理目錄時,可以使用?System.IO?命名空間中的?Directory?和?DirectoryInfo?類來執(zhí)行各種目錄操作,本文主要介紹了c#中directory 和directoryinfo的使用小結(jié),感興趣的可以了解一下2024-02-02
c# 基于GMap.NET實現(xiàn)電子圍欄功能(WPF版)
這篇文章主要介紹了c# 基于GMap.NET實現(xiàn)電子圍欄功能(WPF版),幫助大家更好的理解和學習使用c#,感興趣的朋友可以了解下2021-03-03
C#使用linq計算執(zhí)行元素在列表中出現(xiàn)次數(shù)的方法
這篇文章主要介紹了C#使用linq計算執(zhí)行元素在列表中出現(xiàn)次數(shù)的方法,涉及C#使用linq擴展進行列表查詢的技巧,需要的朋友可以參考下2015-04-04
C#中String StringBuilder StringBuffer類的用法
這篇文章給大家簡單介紹下C#中String StringBuilder StringBuffer三個類的用法,需要的的朋友參考下吧2017-05-05
C#窗口轉(zhuǎn)向方式(由一個窗口,跳轉(zhuǎn)到另一個窗口)
這篇文章主要介紹了C#窗口轉(zhuǎn)向方式(由一個窗口,跳轉(zhuǎn)到另一個窗口)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07
C#抓取網(wǎng)絡(luò)圖片保存到本地的實現(xiàn)方法
下面小編就為大家分享一篇C#抓取網(wǎng)絡(luò)圖片保存到本地的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01

