Browse Source

switch sample logic to AudioSample

develop^2
Dslak 6 years ago
parent
commit
f6de6dbbb7
  1. 88
      Processing/Processing.pde

88
Processing/Processing.pde

@ -1,84 +1,92 @@
import processing.serial.*; import processing.serial.*;
import gohai.glvideo.*; import gohai.glvideo.*;
import ddf.minim.*; import ddf.minim.*;
import ddf.minim.ugens.*;
String[] langs = {"NONE","Italian","English","Spanish","German","French","Russian"};
int langsN = langs.length;
Minim minim; Minim minim;
AudioPlayer[] soundfile = {null,null,null,null,null,null,null};
AudioOutput out;
AudioSample [] sample = new AudioSample[langsN];
GLMovie video; GLMovie video;
Serial myPort; Serial myPort;
String dataIn = ""; String dataIn = "";
char linefeed = '\n'; char linefeed = '\n';
int currentLang = 0; int currentLang = 0;
int millis = 0;
boolean isPlaying = false;
int ms = 0; int ms = 0;
String[] langs = {"NONE","Italian","English","Spanish","German","French","Russian"};
void setup() { void setup() {
size(1024, 768, P2D);
size(1920, 1080, P2D);
myPort = new Serial(this, "/dev/ttyUSB0", 9600);
minim = new Minim(this); minim = new Minim(this);
for(int i=0; i<langs.length; i++) {
println("Loading language file: "+langs[i]+".aiff");
soundfile[i] = minim.loadFile(langs[i]+".aiff");
out = minim.getLineOut();
for(int i=0; i<langsN; i++) {
sample[i] = minim.loadSample( langs[i]+".aiff" );
sample[i].stop();
} }
delay(5000);
myPort = new Serial(this, "/dev/ttyUSB0", 9600);
//delay(5000);
video = new GLMovie(this, "loop.mp4"); video = new GLMovie(this, "loop.mp4");
video.loop(); video.loop();
println("Ready!"); println("Ready!");
} }
void draw() { void draw() {
background(0); background(0);
isPlaying = millis >= millis();
if (video.available()) { if (video.available()) {
video.read(); video.read();
} }
image(video, 0, 0, width, height); image(video, 0, 0, width, height);
if(soundfile[currentLang].isPlaying()) {
if(isPlaying) {
ms = ms < 255 ? ms+1 : 255; ms = ms < 255 ? ms+1 : 255;
/*
textAlign(LEFT, CENTER);
text("Playing",10,10);
*/
} else { } else {
ms = ms > 0 ? ms-1 : 0; ms = ms > 0 ? ms-1 : 0;
} }
tint(255, ms); tint(255, ms);
/*
float sw = textWidth(langs[currentLang]);
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);
*/
}
void serialEvent(Serial thisPort) {
printLanguage();
if(myPort.available() > 0) { if(myPort.available() > 0) {
dataIn = myPort.readStringUntil(linefeed); dataIn = myPort.readStringUntil(linefeed);
if (dataIn != null) { if (dataIn != null) {
String[] split = dataIn.split("\t"); String[] split = dataIn.split("\t");
currentLang = parseInt(trim(split[1]));
for(int i=0; i<langs.length; i++) {
soundfile[i].pause();
currentLang = split.length > 1 ? parseInt(trim(split[1])) : 0;
for(int i=0; i<langsN; i++) {
sample[i].stop();
} }
soundfile[currentLang].rewind();
soundfile[currentLang].play();
println(dataIn+" - "+split[0]+" - "+split[1]+" -> "+currentLang);
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);
}
} }

Loading…
Cancel
Save