首页 > 代码库 > 文字转换为语音VB.NEt实现
文字转换为语音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
本文出自 “王者晨风” 博客,请务必保留此出处http://10882708.blog.51cto.com/10872708/1890438
文字转换为语音VB.NEt实现
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。