Imports System.Speech.Synthesis Imports SpeechLib Public Class Form1 Public Sub New() ' 此調(diào)用是 Windows 窗體設(shè)計器所必需的。 InitializeComponent() ' 在 InitializeComponent() 調(diào)用之后添加任何初始化。 End Sub '分別用兩種方法實現(xiàn) Dim ss As SpeechSynthesizer '定義一個語音引擎訪問全局變量 Dim voice As SpVoice = New SpVoice '調(diào)用第三方工具庫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) '設(shè)置中文語音 'voice.Voice = voice.GetVoices(String.Empty, String.Empty).Item(1) '設(shè)置英文語音,只讀英文 ' voice.Rate = trackBarSpeed.Value '設(shè)置語速 'voice.Volume = trackBarVolumn.Value '設(shè)置音量 ss.SelectVoice(ComboxVoice.SelectedItem) '選擇語音引擎 ss.Rate = trackBarSpeed.Value '設(shè)置語速 ss.Volume = trackBarVolumn.Value '設(shè)置音量 'voice.Speak(txtMsg.Text, SpeechVoiceSpeakFlags.SVSFDefault) '同步朗讀 ' voice.Speak(txtMsg.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync) '異步朗讀 ss.SpeakAsync(txtMsg.Text) '異步發(fā)出語音 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() '繼續(xù)播放 '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" '設(shè)置文件類型為語音文件(.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() '應(yīng)用退出 End Sub End Class
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動態(tài)BGP最優(yōu)骨干路由自動選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機房獨有T級流量清洗系統(tǒng)配攻擊溯源,準確進行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動現(xiàn)已開啟,新人活動云服務(wù)器買多久送多久。
創(chuàng)新互聯(lián)建站是一家專注于做網(wǎng)站、成都網(wǎng)站建設(shè)與策劃設(shè)計,北票網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:北票等地區(qū)。北票做網(wǎng)站價格咨詢:028-86922220