imports system.speech.synthesisimports speechlibpublic class form1 Public sub new () ' This call is Windows Required by the form designer. initializecomponent () ' Add any initialization after initializecomponent () call. End Sub ' implement     DIM SS in two different ways As SpeechSynthesizer ' defines a speech engine to access global variables Dim voice As spvoice = new spvoice ' Call the third-party tool library speechlib private sub Form1_Load (Sender as object, e as eventargs) Handles MyBase.Load ss = new speechsynthesizer () ' instantiation dim voicestring as string = "" "defines a string For Each iv As Installedvoice in ss. Getinstalledvoices () ' traverse the installed speech engine COMBOXVOICE.ITEMS.ADD (Iv. Voiceinfo.name) ' add its name to the combo box Next ComboxVoice.SelectedIndex = 0 ' show first End by default Sub private sub buttonread_click (Sender as object, e as eventargs) handles buttonread.click voice. Voice = voice. Getvoices (String.empty, string.empty). Item (0) ' Set up Chinese speech ' voice. Voice = voice. Getvoices (String.empty, string.empty). Item (1) ' Set English voice, read-only English ' voice.rate = trackbarspeed.value ' Set speech speed ' voice. volume = trackbarvolumn.value ' Set the volume ss. Selectvoice (comboxvoice.selecteditem) ' Select Speech engine ss. rate = trackbarspeed.value ' Set the speed ss. volume = trackbarvolumn.value ' Set volume ' Voice. Speak (txtmsg.text, speechvoicespeakflags.svsfdefault) ' Synchronous reading ' voice. Speak (Txtmsg.text, speechvoicespeakflags.svsflagsasync) ' Asynchronous reading ss. Speakasync (Txtmsg.text) ' Asynchronous voice End Sub Private Sub buttonpause_click (Sender as object, e as eventargs) Handles buttonpause.click ss. Pause () suspend play voice. Pause () end sub private sub buttoncontinue_click ( Sender as object, e as eventargs) Handles ButtonContinue.Click ss. Resume () ' Continue playing ' voice. Resume () end sub private sub buttonrecord_click ( Sender as object, e as eventargs) Handles ButtonRecord.Click Dim ss As SpeechSynthesizer = New SpeechSynthesizer () ' defines a local variable         SS. Rate = trackbarspeed.value ss. Volume = trackbarvolumn.value &nbsP; dim sfd as savefiledialog = new savefiledialog () ' Defines a file Save prompt box, and instantiates         SFD. filter = "Wave files|*.wav" "settings file type is voice file (. wav)  IF SFD. showdialog = dialogresult.ok then ' If the file name is selected ss. Setoutputtowavefile (SFD). FileName) ' output audio file             SS. Speak (Txtmsg.text) ss. Setoutputtodefaultaudiodevice () MessageBox.Show ("Complete recording ~ ~", "Tips") End If end sub private sub buttonclose_click (sender As Object, e as evEntargs) handles buttonclose.click application.exit () ' app exit end subend class
This article is from the "King Breeze" blog, please be sure to keep this source http://10882708.blog.51cto.com/10872708/1890438
Text conversion to Speech vb.net implementation