//------------------------------------------------------------------------------ // name: etude1.ck //------------------------------------------------------------------------------ // Load model Word2Vec model; // me.dir() + "glove-wiki-gigaword-50-tsne-2.txt" => string filepath; me.dir() + "glove-wiki-gigaword-50-pca-3-filtered.txt" => string filepath; // me.dir() + "glove-wiki-gigaword-50.txt" => string filepath; if ( !model.load( filepath ) ) { <<< "cannot load model:", filepath >>>; me.exit(); } 7 => int K_NEAREST; // Poem parameters 5 => int MIN_WORDS_PER_LINE; 9 => int MAX_WORDS_PER_LINE; 4 => int LINES_PER_STANZA; 5 => int NUM_SECTIONS; // Timing Parameters 200::ms => dur T_WORD; // Sound Parameters Wurley voc => JCRev r => dac; // initial settings 220.0 => voc.freq; 0.95 => voc.gain; .8 => r.gain; .1 => r.mix; 36 => int PITCH_BASE; // Variables ConsoleInput in; StringTokenizer tok; string line[0]; string words[K_NEAREST]; for ( int s; s < NUM_SECTIONS; s++ ) { in.prompt( ">" ) => now; while( in.more() ) { line.clear(); tok.set( in.getLine() ); while( tok.more() ) { line << tok.next().lower(); } if( line.size() ) { execute( line ); } } } fun void execute( string input[] ) { string alt[input.size()]; for ( int i; i < input.size(); i++ ) { input[i] => alt[i]; } for (int i; i < LINES_PER_STANZA; i++) { for (int j; j < input.size(); j++) { model.getSimilar( alt[j], words.size(), words ); Math.random2(1, words.size()-1) => int index; words[index] => string alt_word; say(words[index]); play(PITCH_BASE + (12 * index/2)); wait(T_WORD * (index)); words[index] => alt[j]; } chout <= IO.newline(); chout.flush(); } chout <= IO.newline(); chout.flush(); } // say a word with space after fun void say( string word ) { say( word, " " ); } // say a word fun void say( string word, string append ) { // print it chout <= word <= append; chout.flush(); } // sonify fun void play( int pitch ) { play( pitch, Math.random2f(.8,1) ); } // sonify fun void play( int pitch, float velocity ) { // convert pitch to frequency and set it pitch => Std.mtof => voc.freq; // note on velocity => voc.noteOn; } // wait fun void wait() { wait( T_WORD ); } // wait fun void wait( dur T ) { // let time pass, let sound...sound T => now; }