1 Previous Next 

.Net 3.0 and later: Text to Speech


The .Net Framework 3.0 has added some managed Text to Speech functions.  For this example you to add a reference to System.Speech.  I have placed a Listbox (to show the available voices on your machine), textbox, and button on a form.  When you click on the button your computer will say the text in your textbox in the voice selected in the listbox.

Imports System.Speech.Synthesis

Public Class Form1

    Private Sub btnSay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSay.Click
        Dim spk As New SpeechSynthesizer
        spk.SelectVoice(lstVoice.SelectedItem.ToString)
        spk.Speak(txtSay.Text)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim spk As New SpeechSynthesizer
        For Each voice As InstalledVoice In spk.GetInstalledVoices
            lstVoice.Items.Add(voice.VoiceInfo.Name)
        Next
        lstVoice.SelectedIndex = 0
        txtSay.Text = "Hello World!"
    End Sub
End Class




1 Previous Next