.Net3.0实现文本语音朗读的方法

来源:百度文库 编辑:神马文学网 时间:2024/04/30 11:47:36
.Net3.0实现文本语音朗读的方法作者:VB-Tips    来源:VB-Tips     更新时间:2009-10-20

.Net3.0实现文本语音朗读的方法

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  '更多.net源码和实例,来自[乐 博 网 www.lob.cn]

    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