Skip to content

Instantly share code, notes, and snippets.

Created October 15, 2016 02:07
import guru.ttslib.*;
TTS tts; //declare instance for voice 1
TTS tts2; //declare instance for voice 2
void setup() {
size(100,100);
smooth();
tts = new TTS(); // construct each instance
tts2 = new TTS();
}
void draw() {
background(255);
fill(255);
ellipse( 35, 30, 25, 35 );
ellipse( 65, 30, 25, 35 );
fill(0);
ellipse( 40, 35, 10, 10 );
ellipse( 60, 35, 10, 10 );
noFill();
arc(50,50,50,50,0,PI);
}
void mousePressed() {
tts.setPitch(110);
tts.setPitchRange(1);
tts.speak("this is melody");
thread("voice2"); // each voice = separate thread; trigger that thread to start by calling it here
tts.setPitch(110);
tts.setPitchRange(1);
tts.speak("this is harmony");
}
// thread for second voice (tts2)
void voice2() {
delay(100);
tts2.setPitch(131);
tts2.setPitchRange(1);
tts2.speak("this is harmony");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment