Skip to content

Instantly share code, notes, and snippets.

@victorloux
Created October 4, 2016 17:10
Show Gist options
  • Save victorloux/fc748e2579ffc1ccf8a04668dee9f3f1 to your computer and use it in GitHub Desktop.
Save victorloux/fc748e2579ffc1ccf8a04668dee9f3f1 to your computer and use it in GitHub Desktop.
Use the Mac's text-to-speech (VoiceOver) from a Processing sketch
// Note: this is MacOS X only, keep that in mind if you want something portable
// but it's a very easy way to prototype a project using TTS
// Possible voices: "Agnes", "Albert", "Alex", "Bruce", "Fiona", "Fred", "Kathy",
// "Princess", "Ralph", "Vicki", "Victoria"
// Weird voices: "Bad News", "Bahh", "Bells", "Boing", "Bubbles", "Cellos", "Deranged",
// "Good News", "Hysterical", "Junior", "Pipe Organ", "Trinoids", "Whisper", "Zarvox"
//
// to see all installed voices, in a terminal type: `say -v ?`
// Parameters
final String voice = "Alex";
final String rate = "180"; // this must be a string (in quotes) not an int!
String sayText;
void setup() {
// your normal setup here...
}
void draw() {
// change this variable to what you need during the loop
sayText = "Text to be spoken here";
// All the code say the text, block the execution
// of the Processing sketch until it's done, then continue (ie loop again).
// This means that the text will be played over and over, so you may
// want to move this under a condition
try {
String[] params = { "/usr/bin/say", "-r", rate, "-v", voice, sayText };
exec(params).waitFor();
} catch(Exception e) {
println(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment