您好,登錄后才能下訂單哦!
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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。