article

Make a companion (kinda)

Email
Submitted on: 1/3/2015 12:37:00 AM
By: everlasting (from psc cd)  
Level: Intermediate
User Rating: By 2 Users
Compatibility: C++ (general), Microsoft Visual C++
Views: 1844
 
     Have you ever needed a to hear something from your computer besides that grinding it makes and the humming? MAKE IT TALK!!!

 
				

Introduction

Programming is basically makeing the computer bow at your every wim. You can make your computer do everything, EVEN TALK! Making your computer speak isnt that hard and you can have it talkin in less than 10 min.

Download this now!!!

If you dont your never gonna be able to compile this code. www.microsoft.com/speech

Finally it begins

You can make this happen in nearly any computer language. I just so happen to know C++, so thats what I use.
    To begin open Microsoft Visual C++.
      Start a new project, for this tutorial I am making a windows 32 Application. Make a name for it that will make sence for later use (I named mine "tutorialtts")
        Choose the radio button that says "a simple windows 32 application" (the middle one)

      Coding

      Now that youve got you environment set up, we can begin coding. The first thing you have to do is open up StdAfx.h there will be a line that says

      //TODO ADD ADITIONAL HEADERS HERE

      add the following code on the line that is directly beneath that line

      #define _ATL_APARTMENT_THREADED

      //Dont change anything!!!

      #include < atlbase.h>

      extern CComModule _Module;/

      #include < atlcom.h>

      now we need to rely on the compiler to do a job for us.

      Under go the the menu "project > Settings". Click on the C++ tag near the top of the dialog box

      Choose "Preproccesser" from the drop-down form. and in the "additional include directories" box add this

      C:\Program Files\Microsoft Speech SDK 5.1\Include.

      Next go one tab over to the "Link" tab, in the category box choose "Input" in the first box ("Object/library modules") add sapi.lib.

      In the additional library path add

      "C:\Program Files\Microsoft Speech SDK 5.1\Lib\i386"

      Choose the OK button

      I lied, this is the actual coding part

      Open the file projectname.cpp and add this code

      #include

      #include

      int main(int argc, char* argv[])

      {

      ISpVoice * pVoice = NULL;

      if (FAILED(::CoInitialize(NULL)))

      return FALSE;

      HRESULT hr = CoCreateInstance

      (CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, <(void **)&pVoice);

      if( SUCCEEDED( hr ) )

      {

      hr = pVoice->Speak(L"Hey, I can say what ever you want.", 0, NULL);

      // Change pitch

      hr = pVoice->Speak(L"My voice can even drop pitches.", SPF_IS_XML, NULL );

      pVoice->Release();

      pVoice = NULL;

      }

      ::CoUninitialize();

      return TRUE;

      }

      This code initializes COM and sets up what the program will say and makes it says it, thats all. Thats all the code you need to add to the entire project, nothing more, maybe less(depends on what you are going for)

      If you need the files I made go to my website.

      Note

      This tutorial is also included in the files you need to compile these files (install them all the way before you send any complaints)


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.