Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Processing 2: Creative Coding Hotshot

You're reading from   Processing 2: Creative Coding Hotshot Learn Processing with exciting and engaging projects to make your computer talk, see, hear, express emotions, and even design physical objects

Arrow left icon
Product type Paperback
Published in May 2013
Publisher Packt
ISBN-13 9781782166726
Length 266 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Nikolaus Gradwohl Nikolaus Gradwohl
Author Profile Icon Nikolaus Gradwohl
Nikolaus Gradwohl
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Processing 2: Creative Coding Hotshot
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Romeo and Juliet FREE CHAPTER 2. The Stick Figure Dance Company 3. The Disco Dance Floor 4. Smilie-O-Mat 5. The Smilie-O-Mat Controller 6. Fly to the Moon 7. The Neon Globe 8. Logfile Geo-visualizer 9. From Virtual to Real Index

Making Processing talk


Since Processing has no speaking capabilities out of the box, our first task is adding an external library using the new Processing Library Manager. We will use the ttslib package, which is a wrapper library around the FreeTTS library.

We will also create a short, speaking Processing sketch to check the installation.

Engage Thrusters

  1. Processing can be extended by contributed libraries. Most of these additional libraries can be installed by navigating to Sketch | Import Library… | Add Library..., as shown in the following screenshot:

  2. In the Library Manager dialog, enter ttslib in the search field to filter the list of libraries.

  3. Click on the ttslib entry and then on the Install button, as shown in the following screenshot, to download and install the library:

  4. To use the new library, we need to import it to our sketch. We do this by clicking on the Sketch menu and choosing Import Library... and then ttslib.

  5. We will now add the setup() and draw() methods to our sketch. We will leave the draw() method empty for now and instantiate a TTS object in the setup() method. Your sketch should look like the following code snippet:

    import guru.ttslib.*;
    
    TTS tts;
    void setup() {
      tts = new TTS();
    }
    
    void draw() {
    }

    Tip

    Downloading the example code

    You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

  6. Now we will add a mousePressed() method to our sketch, which will get called if someone clicks on our sketch window. In this method, we are calling the speak() method of the TTS object we created in the setup() method.

    void mousePressed() {
      tts.speak("Hello, I am a Computer");
    }
  7. Click on the Run button to start the Processing sketch. A little gray window should appear.

  8. Turn on your speakers or put on your headphones, and click on the gray window. If nothing went wrong, a friendly male computer voice named kevin16 should greet you now.

Objective Complete - Mini Debriefing

In steps 1 to 3, we installed an additional library to Processing. The ttslib is a wrapper library around the FreeTTS text-to-speech engine.

Then we created a simple Processing sketch that imports the installed library and creates an instance of the TTS class. The TTS objects match the speakers we need in our sketches. In this case, we created only one speaker and added a mousePressed() method that calls the speak() method of our tts object.

You have been reading a chapter from
Processing 2: Creative Coding Hotshot
Published in: May 2013
Publisher: Packt
ISBN-13: 9781782166726
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image