-
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