If you’re on OSX, you have access to a text to speech command named
say. This command typically lives at /usr/bin/say and it lets you read text using a robot voice. If you’re unfamiliar with
say, open up Terminal and type the following:
“say you are the master”
Assuming your speakers aren’t muted, you should here a robot voice say “you are my master”. The OSX
say command has many voices built in which you can see by running this command:
“say -v ?”
And now for the magic. Say you want your
Processing sketch to speak. No problem, here’s the source code to a simple sample of how to do this.
// Begin Processing Sketch
void setup() {
size(200, 200);
text(“Turn up your sound”, 5, 100);
text(“and then click me”, 5, 120);
}
void draw() {
// draw() must be present for mousePressed() to work
}
void mousePressed() {
String[] cmd = { “/usr/bin/say”, “What’s shaking bacon?” };
exec(cmd);
println(“mousePressed “);
}
// end sketch