您好,登錄后才能下訂單哦!
Imports System.Speech.Synthesis Imports SpeechLib Public Class Form1 Public Sub New() ' 此調(diào)用是 Windows 窗體設(shè)計(jì)器所必需的。 InitializeComponent() ' 在 InitializeComponent() 調(diào)用之后添加任何初始化。 End Sub '分別用兩種方法實(shí)現(xiàn) Dim ss As SpeechSynthesizer '定義一個(gè)語(yǔ)音引擎訪問全局變量 Dim voice As SpVoice = New SpVoice '調(diào)用第三方工具庫(kù)SpeechLib Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ss = New SpeechSynthesizer() '實(shí)例化 Dim voicestring As String = "" '定義一個(gè)字符串 For Each iv As InstalledVoice In ss.GetInstalledVoices() '遍歷已安裝的語(yǔ)音引擎 ComboxVoice.Items.Add(iv.VoiceInfo.Name) '將其名字添加到組合框 Next ComboxVoice.SelectedIndex = 0 '默認(rèn)顯示第一個(gè) 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è)置中文語(yǔ)音 'voice.Voice = voice.GetVoices(String.Empty, String.Empty).Item(1) '設(shè)置英文語(yǔ)音,只讀英文 ' voice.Rate = trackBarSpeed.Value '設(shè)置語(yǔ)速 'voice.Volume = trackBarVolumn.Value '設(shè)置音量 ss.SelectVoice(ComboxVoice.SelectedItem) '選擇語(yǔ)音引擎 ss.Rate = trackBarSpeed.Value '設(shè)置語(yǔ)速 ss.Volume = trackBarVolumn.Value '設(shè)置音量 'voice.Speak(txtMsg.Text, SpeechVoiceSpeakFlags.SVSFDefault) '同步朗讀 ' voice.Speak(txtMsg.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync) '異步朗讀 ss.SpeakAsync(txtMsg.Text) '異步發(fā)出語(yǔ)音 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() '定義一個(gè)局部變量 ss.Rate = trackBarSpeed.Value ss.Volume = trackBarVolumn.Value Dim sfd As SaveFileDialog = New SaveFileDialog() '定義一個(gè)文件保存提示框,并且實(shí)例化 sfd.Filter = "Wave Files|*.wav" '設(shè)置文件類型為語(yǔ)音文件(.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
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。