Thursday, February 3, 2011

Text to Speech in vb.net

















To Create Text to speech control in vb.net you have to first of all add a new reference.

1)How to add reference in vb project?
a. From Project menu -> add reference

Step 1:- Add Reference.
We Have to add a reference named with "microsoft speech object library" which located in
add reference -> COM -> microsoft speech object library
than press ok.

Step 2:- Taking controls on Form.
  • Take TrackBar , TextBox and Button controls on Form.
Step 3:- Write Coding.

Go to The Coding Window and Write Below Coding.

Imports SpeechLib    '(To Import a New Namespace Named SpeechLib.)
Public Class Form1

    Public WithEvents voice As New SpVoice
    Public Speed_Of_Speech As Integer = 1

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        Try
            Speed_Of_Speech = TrackBar1.Value
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            voice.Rate = Speed_Of_Speech
            voice.Speak(TextBox1.Text, SpeechVoiceSpeakFlags.SVSFDefault)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class

No comments:

Post a Comment