Information Technology Grimoire

Version .0.0.1

IT Notes from various projects because I forget, and hopefully they help you too.

Windows SAPI Using Visual Basic

I’m not a fan of visual basic in general, but there are a few pretty cool things you can do with visual basic. One of them is “speak through your computer” using a script.

This small visual basic script will allow you to type out anything you want spoken. If you prefer a female voice you simply change the text to speech settings on your windows computer. We have used this during conference calls to say silly things in a voice that our co-workers don’t recognize. I’ve seen hacker movies where the computer speaks to the person. How will you use this simple visual basic script?

Female Voice vs Male Voice

If you use windows 10, go to your settings and type in “speech”. You should find the “change text to speech settings”. There is a drop down for different voices. Select the voice you prefer. speech settings speech settings choose voice

Running the Script

vbs icon

Save the code into a file that ends with .vbs and then double click the file. It should speak out in a computer voice and say “This program will talk whatever you type. Try it.”

Then it will loop back to the popup entry and allow you to converse by typing instead of speaking.

Visual Basic Source Code

    DIM message, sapi
    message="This program will talk whatever you type  Try it"
    SET sapi=CreateObject("sapi.spvoice")
    sapi.Speak message

      message=InputBox("Enter the text you want spoken","speak this")
      SET sapi=CreateObject("sapi.spvoice")
      sapi.Speak message

    LOOP until message = ""

If you want to just say 1 thing and close the program or not have it start out with “This program will talk whatever you type..” try the code below

    DIM message, sapi
    message=InputBox("Text to Speak","Speaker")
    SET sapi=CreateObject("sapi.spvoice")
    sapi.Speak message
Last updated on 13 Jul 2019
Published on 13 Jul 2019