Friday, August 27, 2010

VB.NET - How to enable Text To Speech on your application


I found it is cool if a
software would able to speak out, whether it is alerting the user for errors or some other fancy little thing to let your users aware of.

This is a sample code in Visual Basic .NET that enable your program to speak out a word (or sentences) by using System.Speech.Synthesis namespace.

Make sure .NET Framework 3.5 was installed.

Add System.Speech as reference in your project.
Code Snippet:
Imports System.Speech.Synthesis
Module Module1
             Dim tts As New SpeechSynthesizer
     
             Public Sub Main(ByVal arg() As String)
                If  Not arg is Nothing Then
                     For Each t As String In arg
                                tts.SpeakAsync(t)
                    Next
               End If
End Sub
End Module