// make a ConsoleInput ConsoleInput in; // tokenizer StringTokenizer tok; // line string lineAsOneStr; string line[0]; // our default model Word2Vec model; // loading any default here "glove-wiki-gigaword-50.txt" => string filepath; <<< "Poet is loading its words...be still.", "" >>>; // load if( !model.load( me.dir() + filepath ) ) { <<< "cannot load work vectors file...", "" >>>; me.exit(); } "a".charAt(0) => int a_ASCII; fun int char2int( string word, int whichChar ) { // return < 0 if error if( word.length() == 0) return -1; word.lower().charAt(whichChar) - (a_ASCII) => int letter_num ; return letter_num; } SndBuf buffers[26]; for( int i; i < buffers.size(); i++ ) { buffers[i] => dac; 0 => buffers[i].gain; } "abcdefghijklmnopqrstuvwxyz" => string abc; // load all sound files for( int i; i < abc.length(); i++ ) { char2int( abc, i ) => int num; if (num >= 0 && num <= 25) { me.dir() + abc.substring(i,1) + ".wav" => buffers[i].read; } } // spork ~ sayer(); while( true ) { // prompt in.prompt( "give us the word =>" ) => now; // read while( in.more() ) { // remember the input in.getLine() => lineAsOneStr; // get it tok.set( lineAsOneStr ); // clear array line.clear(); // print tokens while( tok.more() ) { // put into array line << tok.next().lower(); } // if non-empty if( line.size() == 2 ) { // execute execute( line ); } else { <<< "you need to say how many words you want from us...", "" >>>; } } } fun void execute( string line[] ) { Std.atoi(line[1]) => int k; string results[k]; model.getSimilar( line[0], k, results ); // print for (0 => int i; i < k; i++) { <<< results[i], "" >>>; speak(results[i]); } <<< "" ,"">>>; 2:: second => now; <<< "sit back, we got this", "" >>>; <<< "" ,"">>>; 2::second => now; do_more(results); } fun void do_more (string results[]) // the, which, part { string line1[5]; // line 1 Math.random2(0, (results.size()-1)) => int choice_index; results[choice_index] => string new_base_word; for (0 => int i; i < 4; i++) { <<< "we choose = " + "'" + new_base_word + "'", "" >>>; new_base_word => line1[i]; 250::ms => now; Math.random2(1,10) => int amount; string choices_results[amount]; model.getSimilar( new_base_word, amount, choices_results ); for (0 => int i; i < amount; i++) { <<< choices_results[i], "" >>>; speak(choices_results[i]); } Math.random2(0, (choices_results.size()-1)) => int choice_index; choices_results[choice_index] => new_base_word; 1::second => now; <<< "" ,"">>>; } 500::ms => now; <<< "...", "">>>; 500::ms => now; <<< "", "">>>; 500::ms => now; <<< "...", "">>>; 500::ms => now; <<< "", "">>>; 500::ms => now; <<< "we're not loading, we're just done", "">>>; 1::second => now; <<< "", "">>>; 500::ms => now; <<< "...", "">>>; 500::ms => now; <<< "", "">>>; 500::ms => now; <<< "unless you want another poem?", "" >>>; <<< "" ,"">>>; } fun void speak( string word ) { for( int i; i < word.length(); i++ ) { char2int( word, i ) => int num; if (num >= 0 && num <= 25) { //<<< num >>>; play_buf(num); } } } fun void play_buf(int num) { buffers[num] @=> SndBuf buf; 0 => buf.pos; Math.random2f(.2,.5) => buf.gain; 1 => buf.rate; Math.random2(50,150) => int timing; timing::ms => now; 10::ms => now; }