Categories

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

Make Your Computer Talk with VB.NET Application (and Source Code)

I was playing around with COM objects in Windows and discovered that I could access the SAPI.SpVoice interface and make Microsoft Windows talk to me. Well needless to say I had to rush and develop and application to do just that. I uploaded a simple applicaton which will just say whatever you type in as an argument. For example SpeakToMeConsole.exe Hello World will make your computer speak the words “Hello World.” The part that really amazes me is that the guts of this program is only 2 lines long, and it can even that can reduced down to 1 line if we create an anonymous instance of SAPI.SpVoice object.

The reason I created it as a console application and not a windows app is because I envisioned this program only really only having a valid function when it’s called from another application. Or even better, you want to spook your girlfriend or parents by making their laptop talk to them when it turns on! Whatever your reasons are, enjoy! Oh and let me know how you use this program in the comments.

Download SpeakToMe App

Download SpeakToMe App

Here is the complete source code to the above application. Let me know what you think in the comments!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'This application was developed by Gerardo Lopez and was downloaded from www.brangle.com
'Complete source code is available at:
'http://www.brangle.com/wordpress/2009/08/make-your-computer-talk-with-vb-net-app-source-code/
 
 
Module Module1
    'We want to make sure we grab any arguments as args so that we speak them    
    Sub Main(ByVal args As String())
        'If there are no arguments UBound will return -1
        'Therefore we want to make sure to let the user know how to run the app if 
        'they don't enter any arguments
        If UBound(args) > -1 Then
 
            'Generate an empty string, we'll use this to concatenate all of our arguments 
            'together so we can pass it to the narrator
            Dim input As String = ""
 
            'Concat all of our arguments together and make sure to put a space in 
            'between them so the words don't run together
            For Each arg As String In args
                input = input + arg + " "
            Next
 
            'Create an object and gain access to the narrator
            Dim voice = CreateObject("SAPI.SpVoice")
            'Tells the narrator what to say
            voice.Speak(input)
        Else
            'The is where we tell the user what to say if they didn't enter any arguments
            Console.WriteLine("No arguments specified")
            Console.WriteLine("Try this instead: SpeakToMe.exe Hello World")
            Console.WriteLine(vbCrLf + vbCrLf + "Visit www.brangle.com for other apps")
        End If
    End Sub
End Module
'The End

To run this program from the command line, you can type in something like the following:

SpeakToMeConsole.exe Hello World

And here is the beautiful one-liner!

1
CreateObject("SAPI.SpVoice").Speak("hello from brangle.com")

1 comment to Make Your Computer Talk with VB.NET Application (and Source Code)

Leave a Reply