ookey-Speech

Interactive Version:

Video Example:

With my project, I wanted to generate something lyrical or poetic.  I was then inspired by Rob Seward’s piece “Death Death Death”. I was curious as to what would happen if different words were inputted rather than death.  I ended up looking into his piece and used the same database as him, which was developed by the University of South Florida. In the end, I used these associations to make something of a poem. These can sometimes turn out poetic and sometimes quite silly. I think the video included shows an example of a poem that transforms from typical poetic language to something much more casual. In the future, I think it would be interesting to connect these words through sentences or, possibly, lyrics.  I’m also glad I was able to get it running in an embedded form.  I would also be curious if I ran this in a reverse order, like Death Death Death, and the inputted word is where the poem ends up.

Code:

// Reference taken from Golan Levin's Rhyming program
 
// Database taken from University of South Florida Free Association Norms
// http://w3.usf.edu/FreeAssociation/AppendixA/index.html
 
// Inspired by Rob Seward's Death Death Death
// http://robseward.com/ddd/
 
 
// The speech recognizer
var mySpeechRecognizer;
var startWord;
 
// The speech synthesizer
var myVoiceSynthesizer;
 
// The RiTa Lexicon
var myRitaLexicon;
 
//association variables
var processed = true;
var nextWord = "";
var associations = [];
var printArray = [];
var timer;
 
//database of word associations
var tableAB;
var tableC;
var tableDF;
var tableGK;
var tableLO;
var tablePR;
var tableS;
var tableTZ;
 
function preload() {
  //my table is comma separated value "csv"
  //and has a header specifying the columns labels
  tableAB = loadTable('https://www.openprocessing.org/sketch/512691/files/AB.csv', 'csv');
	tableC = loadTable('https://www.openprocessing.org/sketch/512691/files/C.csv', 'csv');
	tableDF = loadTable('https://www.openprocessing.org/sketch/512691/files/DF.csv', 'csv');
	tableGK = loadTable('https://www.openprocessing.org/sketch/512691/files/GK.csv', 'csv');
	tableLO = loadTable('https://www.openprocessing.org/sketch/512691/files/LO.csv', 'csv');
	tablePR = loadTable('https://www.openprocessing.org/sketch/512691/files/PR.csv', 'csv');
	tableS = loadTable('https://www.openprocessing.org/sketch/512691/files/S.csv', 'csv');
	tableTZ = loadTable('https://www.openprocessing.org/sketch/512691/files/TZ.csv', 'csv');
}
 
//=========================================
function setup() {
	createCanvas(500, 500);
 
	// Make the speech recognizer
	startWord = "";
	initializeMySpeechRecognizer(); 
 
	// Make the speech synthesizer
	myVoiceSynthesizer = new p5.Speech();
	myVoiceSynthesizer.setVoice(5);
	myVoiceSynthesizer.setRate(.5);
 
	// Create the RiTa lexicon (for rhyming)
	myRitaLexicon = new RiLexicon();
}
 
//=========================================
function initializeMySpeechRecognizer(){
	mySpeechRecognizer = new p5.SpeechRec('en-US'); 
 
	mySpeechRecognizer.continuous = true; // do continuous recognition
	mySpeechRecognizer.interimResults = false; // allow partial recognition 
	mySpeechRecognizer.onResult = parseResult; // recognition callback
	mySpeechRecognizer.start(); // start engine
 
	console.log(mySpeechRecognizer);
}
 
//=========================================
function draw() {
	background('#B3B3D7');
 
	// draw words
	fill('#43464B');
	textFont("Helvetica");
	textSize(25);
	textAlign(CENTER);
	//var printString = printArray.join('\n');
	//text(printString, width/2, height/2);
	for (var x = 0; x < printArray.length; x++) { var posn = printArray.length - x; fill(0, 0, 0, (255 - 20*posn)); text(printArray[x], width/2, 25 + (25*posn)); } findNextWord(startWord); } //========================================= function keyPressed(){ // Press the spacebar to reinitialize the recognizer. // This is helpful in case it freezes up for some reason. // If you have a lot of freezes, consider automating this. initializeMySpeechRecognizer(); startWord = ''; nextWord = ''; printArray = []; } //========================================= function parseResult() { mostRecentConfidence = mySpeechRecognizer.resultConfidence; if (mostRecentConfidence > 0.25){ // some confidence threshold...
		console.log (mySpeechRecognizer.resultString);
 
		// The Recognition system will often append words into phrases.
		// So the hack here is to only use the last word:
		startWord = mySpeechRecognizer.resultString.split(' ').pop();
		startWord = startWord.toLowerCase();
		processed = false;
		printArray = [];
		clearTimeout(timer);
	}
}
 
//=========================================
function findNextWord(){
 
	if ((startWord.length > 0)  && !processed)
	{
		append(printArray, startWord);
		myVoiceSynthesizer.speak(startWord);
		nextWord="";
		associations=[];
		var table;
		var alphabet = startWord.charAt(0);
		alphabet = alphabet;
		if (['a','b'].includes(alphabet))
		{
			table = tableAB;
		}
		if (['c'].includes(alphabet))
		{
			table = tableC;
		}
		if (['d','e', 'f'].includes(alphabet))
		{
			table = tableDF;
		}
		if (['g', 'h', 'i','j','k'].includes(alphabet))
		{
			table = tableGK;
		}
		if (['l','m','n','o'].includes(alphabet))
		{
			table = tableLO;
		}
		if (['p','q','r'].includes(alphabet))
		{
			table = tablePR;
		}
		if (['s'].includes(alphabet))
		{
			table = tableS;
		}
		if (['t','u','v','w','x','y','z'].includes(alphabet))
		{
			table = tableTZ;
		}
 
		for (var r = 0; r < table.getRowCount(); r++) { if (table.getString(r, 0).toLowerCase() == startWord) { append(associations, table.getString(r, 1).toLowerCase().trim()); } } if (associations.length > 0)
		{
			nextWord = associations[Math.floor(Math.random() * associations.length)];
		}
		timer = setTimeout(function(){
  	  startWord = nextWord;
			processed = false;
		}, 3000);
	}
  processed = true;	
}