教你如何用C#制作文字转换成声音程序
程序员文章站
2023-12-16 22:45:58
教你如何用c#制作文字转换成声音程序
在system.speech命名空间下,speechsynthesizer类可以把文字读出来,一起来玩下~~
首先在windows...
教你如何用c#制作文字转换成声音程序
在system.speech命名空间下,speechsynthesizer类可以把文字读出来,一起来玩下~~
首先在windows窗体项目中引入system.speech。界面部分:
后台代码也很简单,只不过调用了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(); } } }