Created
April 16, 2012 04:59
-
-
Save ktibb/2396392 to your computer and use it in GitHub Desktop.
Dictionary Aloud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rita.*; | |
import rita.wordnet.*; | |
import com.getflourish.stt.*; | |
STT stt; | |
String global_txt; | |
//POS tagging | |
String[] words; | |
String selection; | |
RiWordnet wordnet; | |
String [] results; | |
//activate TTS | |
RiSpeech speech; | |
//Create an array list ("uttered phrases" can only hold type Utter) | |
ArrayList<Utter> utterances; | |
ArrayList<WordResult> currentResult; | |
//float velocity=0.03; | |
//float acceleration= 0.001; | |
//float y=30; | |
void setup () { | |
size(1800, 400); | |
// Init STT with default manual record mode | |
stt = new STT(this); | |
stt.enableDebug(); | |
stt.setLanguage("en"); | |
//create/initialize an empty array list | |
utterances=new ArrayList<Utter>(); | |
currentResult=new ArrayList<WordResult>(); | |
textFont(createFont("Arial", 24)); | |
wordnet=new RiWordnet (this); | |
//speech | |
speech = new RiSpeech(this); | |
speech.useMacTTS(); | |
speech.setVoice("Vicki"); | |
speech.speak("Please press a button and speak."); | |
} | |
//iUtter=new Utter("Hold down any key and speak."); | |
//utterances.add(iUtter); | |
//println(utterances.size()); | |
//iUtter.display(); | |
//utterances.get(i)iUtter.display; | |
void draw() { | |
background(0); | |
displayAllUtterances(); | |
fadeAllUtterances(); | |
} | |
//method is called if transciption is successful, Also add to array | |
void transcribe (String txt, float confidence) { | |
global_txt=txt; | |
Utter newUtterance = new Utter(txt); | |
//println(txt); | |
//adding new (modified) utterance to the list array | |
utterances.add(newUtterance); | |
} | |
//display all utterances | |
void displayAllUtterances() { | |
for (int i=0;i<utterances.size(); i++) { | |
//cast the object coming out of the array | |
utterances.get(i).display(); | |
utterances.get(i).tags(); | |
} | |
} | |
//fade all utterances | |
void fadeAllUtterances() { | |
for (int i=0;i<utterances.size(); i++) { | |
//cast the object coming out of the array | |
//displays each word in array list | |
Utter thisUtterance = utterances.get(i); | |
float thisLife = thisUtterance.life; | |
//if it's still alive, fade. If its' not still alive, remove. | |
if (thisLife > 0) { | |
thisUtterance.life = thisUtterance.life - 0.1; | |
} | |
else { | |
utterances.remove(i); | |
} | |
} | |
} | |
// Use any key to begin and end a record | |
void keyPressed () { | |
stt.begin(); | |
} | |
void keyReleased () { | |
stt.end(); | |
for (int i=0;i<utterances.size(); i++) { | |
utterances.remove(i); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Utter { | |
String global_txt; | |
float life=255; | |
float x; | |
float y; | |
float r; | |
float g; | |
float b; | |
//the contructor | |
Utter (String s) { | |
global_txt=s; | |
x=30; | |
r=255; | |
g=255; | |
b=255; | |
} | |
void display () { | |
fill (r, b, g, life); | |
String[]words= global_txt.split(" "); | |
List<String> currentResults = Arrays.asList(words); | |
// println(words); | |
for (int i=0;i<words.length;i++) { | |
text(words[i], x, y+30+(i*25)); | |
// velocity+=acceleration; //increase in velocity | |
// y+= velocity; | |
// if (y>height){ | |
// } | |
} | |
} | |
void tags() { | |
String[]words= global_txt.split(" "); | |
List<String> currentResults = Arrays.asList(words); | |
if (mousePressed==true&&mouseX<400&&mouseY<30) { | |
try { | |
for (int i=0;i<words.length;i++) { | |
results = wordnet.getAllGlosses(words[0], "n"); | |
text (results[i], x+100+(i*30), y+30+(i*25)); | |
println(results[i]); | |
//speech.speak(results[i]); | |
// velocity=0; | |
} | |
} | |
catch(Exception e) { | |
} | |
} | |
if (mousePressed==true&&mouseX<400&&mouseY<55&&mouseY>30) { | |
try { | |
for (int i=0;i<words.length;i++) { | |
results = wordnet.getAllGlosses(words[1], "n"); | |
text (results[i], x+100+(i*30), y+55+(i*25)); | |
// velocity=0; | |
} | |
} | |
catch(Exception e) { | |
} | |
} | |
if (mousePressed==true&&mouseX<400&&mouseY<80&&mouseY>55) { | |
try { | |
for (int i=0;i<words.length;i++) { | |
results = wordnet.getAllGlosses(words[2], "n"); | |
text (results[i], x+100+(i*30), y+80+(i*25)); | |
// velocity=0; | |
} | |
} | |
catch(Exception e) { | |
} | |
} | |
if (mousePressed==true&&mouseX<400&&mouseY<105&&mouseY>80) { | |
try { | |
for (int i=0;i<words.length;i++) { | |
results = wordnet.getAllGlosses(words[3], "n"); | |
text (results[i], x+100+(i*30), y+105+(i*25)); | |
} | |
} | |
catch(Exception e) { | |
} | |
} | |
if (mousePressed==true&&mouseX<400&&mouseY<130&&mouseY>105) { | |
try { | |
for (int i=0;i<words.length;i++) { | |
results = wordnet.getAllGlosses(words[4], "n"); | |
text (results[i], x+100+(i*30), y+130+(i*25)); | |
// velocity=0; | |
} | |
} | |
catch(Exception e) { | |
} | |
} | |
if (mousePressed==true&&mouseX<400&&mouseY<155&&mouseY>130) { | |
try { | |
for (int i=0;i<words.length;i++) { | |
results = wordnet.getAllGlosses(words[5], "n"); | |
text (results[i], x+100+(i*30), y+155+(i*25)); | |
// velocity=0; | |
} | |
} | |
catch(Exception e) { | |
} | |
} | |
if (mousePressed==true&&mouseX<400&&mouseY<170&&mouseY>155) { | |
try { | |
for (int i=0;i<words.length;i++) { | |
results = wordnet.getAllGlosses(words[6], "n"); | |
text (results[i], x+100+(i*30), y+170+(i*25)); | |
// velocity=0; | |
} | |
} | |
catch(Exception e) { | |
} | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WordResult{ | |
String word; | |
float life=255; | |
float xPos; | |
float yPos; | |
//the contructor | |
WordResult (String w) { | |
word=w; | |
xPos=30; | |
yPos=50; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment