You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
1.8 KiB

import processing.serial.*;
import gohai.glvideo.*;
6 years ago
import ddf.minim.*;
import ddf.minim.ugens.*;
String[] langs = {"NONE","Italian","English","Spanish","German","French","Russian"};
int langsN = langs.length;
6 years ago
Minim minim;
AudioOutput out;
AudioSample [] sample = new AudioSample[langsN];
GLMovie video;
Serial myPort;
String dataIn = "";
char linefeed = '\n';
int currentLang = 0;
int millis = 0;
boolean isPlaying = false;
int ms = 0;
void setup() {
size(1920, 1080, P2D);
myPort = new Serial(this, "/dev/ttyUSB0", 9600);
6 years ago
minim = new Minim(this);
out = minim.getLineOut();
for(int i=0; i<langsN; i++) {
sample[i] = minim.loadSample( langs[i]+".aiff" );
sample[i].stop();
}
6 years ago
//delay(5000);
video = new GLMovie(this, "loop.mp4");
video.loop();
println("Ready!");
}
void draw() {
background(0);
isPlaying = millis >= millis();
if (video.available()) {
video.read();
}
image(video, 0, 0, width, height);
if(isPlaying) {
ms = ms < 255 ? ms+1 : 255;
} else {
ms = ms > 0 ? ms-1 : 0;
}
tint(255, ms);
printLanguage();
if(myPort.available() > 0) {
dataIn = myPort.readStringUntil(linefeed);
if (dataIn != null) {
String[] split = dataIn.split("\t");
currentLang = split.length > 1 ? parseInt(trim(split[1])) : 0;
for(int i=0; i<langsN; i++) {
sample[i].stop();
}
millis = millis() + sample[currentLang].length();
sample[currentLang].trigger();
println("Speech " + langs[currentLang]);
}
}
//println(sample[currentLang].length(), millis, millis());
}
void printLanguage() {
fill(255);
stroke(255);
textSize(16);
textAlign(CENTER, CENTER);
text("Selected language:", width/2, (height/2)-50);
textSize(22);
text(langs[currentLang], width/2, height/2);
if(isPlaying) {
textAlign(LEFT, CENTER);
text("Playing",10,10);
}
}