How to make a text to speech program in vb.net



Imports System.Drawing.Font
 Imports System.Drawing.FontFamily
Imports System.Drawing.FontConverter
 Imports System.Speech.Synthesis
 Imports System.Collections.ObjectModel

 Public Class Text_To_Speech
 Private p_objSynth As New SpeechSynthesizer
 Dim w As Integer = Screen.PrimaryScreen.Bounds.Width
 Dim h As Integer = Screen.PrimaryScreen.Bounds.Height

 Private Sub BindCombo()
 ComboBox2.DrawMode = DrawMode.OwnerDrawFixed
 ComboBox2.Font = New Font("Microsoft Sans Serif, 11.25pt", 11.25)
 ComboBox2.ItemHeight = 20
 Dim objFontFamily As FontFamily
 Dim objFontCollection As System.Drawing.Text.FontCollection
 Dim tempFont As Font
objFontCollection = New System.Drawing.Text.InstalledFontCollection()
For Each objFontFamily In objFontCollection.Families
ComboBox2.Items.Add(objFontFamily.Name)
 Next
 End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim objvoices As ReadOnlyCollection(Of InstalledVoice) = p_objSynth.GetInstalledVoices(Globalization.CultureInfo.CurrentCulture)
        Dim objvoiceInformation As VoiceInfo = objvoices(0).VoiceInfo
        For Each tmpvoice As InstalledVoice In objvoices
objvoiceInformation = tmpvoice.VoiceInfo
            cmbInstalled.Items.Add(objvoiceInformation.Name.ToString)
        Next
       
     Next
        Dim i As Integer
        For i = 10 To 100
            ComboBox1.Items.Add(i)
        Next
        BindCombo()

'Dim Reply As MsgBoxStyle = MsgBox("Some Prompt Text", vbOKOnly + vbInformation + vbMsgBoxSetForeground + vbSystemModal, "Some Title")

        'MessageBox.Show(Reply)
        txtVoiceText.Width = w - 10
        txtVoiceText.Height = h - 200

        Label3.Top = h - 80
        btnRate.Left = 10
        btnRate.Top = h - 100
        Label2.Top = h - 80
        Label2.Left = 400
        btnVolume.Left = 300
        btnVolume.Top = h - 100
        Label4.Top = h - 70
        Label4.Left = 700
        cmbInstalled.Left = 600
        cmbInstalled.Top = h - 100
        Button1.Left = 900
        Button1.Top = h - 100

        Button2.Left = 1050
        Button2.Top = h - 100

    End Sub



    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If (cmbInstalled.Text = "Choose Voice") Then
            MsgBox("Please Choose Voice")
        Else

            p_objSynth.SelectVoice(cmbInstalled.Text)
            p_objSynth.SpeakAsync(txtVoiceText.Text)
        End If

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        p_objSynth.SpeakAsyncCancelAll()
    End Sub

    Private Sub btnRate_ValueChanged(sender As Object, e As EventArgs) Handles btnRate.ValueChanged
        p_objSynth.Volume = btnVolume.Value
    End Sub

    Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

    End Sub

    Private Sub btnRate_Scroll(sender As Object, e As EventArgs) Handles btnRate.Scroll

    End Sub

    Private Sub btnVolume_ValueChanged(sender As Object, e As EventArgs) Handles btnVolume.ValueChanged
        p_objSynth.Volume = btnVolume.Value
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If ComboBox1.Text = "Font Size" Or ComboBox2.Text = "Font Size" Or ComboBox3.Text = "Font Color" Or ComboBox4.Text = "Back Color" Then
            MsgBox("Please Choose All Fileds", MsgBoxStyle.OkCancel, "BHUP SINGH")
        ElseIf ComboBox3.Text = ComboBox4.Text Then
            MsgBox("Background and Forecolore same", MsgBoxStyle.YesNo, "BHUP SINGH SINGLA")


        Else

            Dim s As Integer
            s = Val(ComboBox1.Text)
            Dim fs As New FontStyle
            If CheckBox1.Checked = True Then
                fs = fs Or FontStyle.Bold
            End If
            If CheckBox2.Checked = True Then
                fs = fs Or FontStyle.Italic
            End If
            If CheckBox3.Checked = True Then
                fs = fs Or FontStyle.Underline

            End If

            Dim fo As New Font(ComboBox2.Text, s, fs)
            txtVoiceText.Font = fo

            Dim co As Color
            co = Color.FromName(ComboBox3.Text)
            txtVoiceText.ForeColor = co
            Dim ba As Color
            ba = Color.FromName(ComboBox4.Text)
            txtVoiceText.BackColor = ba




        End If


    End Sub
    Private Sub ComboBox2_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox2.DrawItem
        e.DrawBackground()
        If (e.State And DrawItemState.Focus) <> 0 Then
            e.DrawFocusRectangle()
        End If
        Dim objBrush As Brush = Nothing
        Try
            objBrush = New SolidBrush(e.ForeColor)
            Dim _FontName As String = ComboBox2.Items(e.Index)
            Dim _font As Font
            Dim _fontfamily = New FontFamily(_FontName)
            If _fontfamily.IsStyleAvailable(FontStyle.Regular) Then
                _font = New Font(_fontfamily, 14, FontStyle.Regular)
            ElseIf _fontfamily.IsStyleAvailable(FontStyle.Bold) Then
                _font = New Font(_fontfamily, 14, FontStyle.Bold)
            ElseIf _fontfamily.IsStyleAvailable(FontStyle.Italic) Then
                _font = New Font(_fontfamily, 14, FontStyle.Italic)
            End If
            e.Graphics.DrawString(_FontName, _font, objBrush, e.Bounds)
        Finally
            If objBrush IsNot Nothing Then
                objBrush.Dispose()
            End If
            objBrush = Nothing
        End Try
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        txtVoiceText.Text = ""
    End Sub
End Class





text to speach

Comments

Post a Comment

Popular posts from this blog

How to make an Automated Refreshing Web Browser Using VB.NET