文字转换为语音VB.NEt实现-创新互联
Imports System.Speech.Synthesis Imports SpeechLib Public Class Form1 Public Sub New() ' 此调用是 Windows 窗体设计器所必需的。 InitializeComponent() ' 在 InitializeComponent() 调用之后添加任何初始化。 End Sub '分别用两种方法实现 Dim ss As SpeechSynthesizer '定义一个语音引擎访问全局变量 Dim voice As SpVoice = New SpVoice '调用第三方工具库SpeechLib Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ss = New SpeechSynthesizer() '实例化 Dim voicestring As String = "" '定义一个字符串 For Each iv As InstalledVoice In ss.GetInstalledVoices() '遍历已安装的语音引擎 ComboxVoice.Items.Add(iv.VoiceInfo.Name) '将其名字添加到组合框 Next ComboxVoice.SelectedIndex = 0 '默认显示第一个 End Sub Private Sub ButtonRead_Click(sender As Object, e As EventArgs) Handles ButtonRead.Click voice.Voice = voice.GetVoices(String.Empty, String.Empty).Item(0) '设置中文语音 'voice.Voice = voice.GetVoices(String.Empty, String.Empty).Item(1) '设置英文语音,只读英文 ' voice.Rate = trackBarSpeed.Value '设置语速 'voice.Volume = trackBarVolumn.Value '设置音量 ss.SelectVoice(ComboxVoice.SelectedItem) '选择语音引擎 ss.Rate = trackBarSpeed.Value '设置语速 ss.Volume = trackBarVolumn.Value '设置音量 'voice.Speak(txtMsg.Text, SpeechVoiceSpeakFlags.SVSFDefault) '同步朗读 ' voice.Speak(txtMsg.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync) '异步朗读 ss.SpeakAsync(txtMsg.Text) '异步发出语音 End Sub Private Sub ButtonPause_Click(sender As Object, e As EventArgs) Handles ButtonPause.Click ss.Pause() '暂停播放 'voice.Pause() End Sub Private Sub ButtonContinue_Click(sender As Object, e As EventArgs) Handles ButtonContinue.Click ss.Resume() '继续播放 'voice.Resume() End Sub Private Sub ButtonRecord_Click(sender As Object, e As EventArgs) Handles ButtonRecord.Click Dim ss As SpeechSynthesizer = New SpeechSynthesizer() '定义一个局部变量 ss.Rate = trackBarSpeed.Value ss.Volume = trackBarVolumn.Value Dim sfd As SaveFileDialog = New SaveFileDialog() '定义一个文件保存提示框,并且实例化 sfd.Filter = "Wave Files|*.wav" '设置文件类型为语音文件(.wav) If sfd.ShowDialog = DialogResult.OK Then '如果选择了文件名 ss.SetOutputToWaveFile(sfd.FileName) '输出音频文件 ss.Speak(txtMsg.Text) ss.SetOutputToDefaultAudioDevice() MessageBox.Show("完成录音~~", "提示") End If End Sub Private Sub ButtonClose_Click(sender As Object, e As EventArgs) Handles ButtonClose.Click Application.Exit() '应用退出 End Sub End Class
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
创新互联建站是一家专注于做网站、成都网站建设与策划设计,北票网站建设哪家好?创新互联建站做网站,专注于网站建设十载,网设计领域的专业建站公司;建站业务涵盖:北票等地区。北票做网站价格咨询:028-86922220名称栏目:文字转换为语音VB.NEt实现-创新互联
本文来源:http://lswzjz.com/article/jpccc.html