zbeok-Speech

I had a lot of struggles with this project, mainly with the limited amount of language play I could do. At first my ideas had a lot to do with semantic meaning behind speech, but given that I would have to pull it off in spectacular fashion in order to make it work, I had to shelve some tidbits for later rethinking. My current idea is a facsimile of a robotic conversation partner that basically tries to parse simple meaning from your words and is ultimately very bad at it. Sometimes they fall asleep, sometimes they really seem like they aren’t getting what you’re saying. I wanted to see how a distinctly non-human being (a computer face) would garner human empathy by doing familiar human things. It can have emotions, but ultimately they’re programmed. I wanted to compare and contrast to the standard robot model of an emotionless being.

In the end, I wasn’t really satisfied with my end product. It’s got a kind of tenuous grasp on the prompt, and doesn’t really get the point across the way I want it to. However, I guess I like the character design. I hope to do more with them later.

SKETCHES:

MEDIA FILES:

VIDEO:

CODE:

s= s.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g," ");
scrt= scrt.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g," ");
bee= bee.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g," ");
spid = spid.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g," ");
kitch = kitch.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g," ");
maschef = maschef.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g," ");
var rm = new RiMarkov(3);
 
var sentiment = new Sentimood();
 
var mic;
var curr;
var start=0;
var mostRecentSpokenWord;
var mostRecentConfidence;
var awake = true;
 
// The speech synthesizer
var myVoice;
 
// The RiTa Lexicon
var myRitaLexicon;
 
//=========================================
function setup() {
	createCanvas(320, 320);
 
	// Make the speech recognizer
	mostRecentConfidence = 0;
	mostRecentSpokenWord = "";
	initializeMySpeechRecognizer(); 
 
	// Make the speech synthesizer
	myVoice = new p5.Speech();
 
		setTimeout(function(){ myVoice.listVoices();
	myVoice.setVoice(6);}, 100);
	// myVoice.setVoice(2);
 
	// Create the RiTa lexicon (for rhyming)
	myRitaLexicon = new RiLexicon();
	rm.loadText(bee);
	rm.loadText(s);
	rm.loadText(scrt);
	rm.loadText(spid);
	rm.loadText(kitch);
	rm.loadText(maschef);
	mic = new p5.AudioIn()
	mic.start();
}
 
//=========================================
function initializeMySpeechRecognizer(){
	myRec = new p5.SpeechRec('en-US'); 
 
	myRec.continuous = true; // do continuous recognition
	// myRec.interimResults = false; // allow partial recognition 
	myRec.onResult = parseResult; // recognition callback
	myRec.start(); // start engine
 
	console.log(myRec);
}
 
//=========================================
function keyPressed(){
	if (key === ' '){
		// 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();
	}
}
 
function draw()
{
	useResult();
 
}
function parseResult() {
	mostRecentConfidence = myRec.resultConfidence;
	if (mostRecentConfidence > 0.5){ // some confidence threshold...
 
		// The Recognition system will often append words into phrases.
		// So the hack here is to only use the last word:
		mostRecentSpokenWord = myRec.resultString.split(' ').pop();
		// bFoundRhymeWithMostRecentWord = false;
	}
}
function useResult()
{
	if(mostRecentSpokenWord!=curr) { 
		continuate();
		console.log(mostRecentSpokenWord);
	}
	var micLevel = mic.getLevel();
	var phr = "";
	if (myRec.resultString) 
		phr = myRec.resultString;
	if (micLevel>0.1 && !awake || match(phr,"wake")){
		console.log("wake!");
		wake();
		awake=true;
		start=millis();
	} else{
		if ((millis()-start)>10000 && awake) {
			if (random([0,1])==0) {
				nodOff();
				console.log("sleep...");
				awake=false;
			} else {
				askThing();
				console.log("asking");
			}
 
			start=millis();
		}
	}
}
 
function continuate() {
	curr=mostRecentSpokenWord;
	var preArr = [mostRecentSpokenWord];
	var cont = rm.getCompletions(preArr);
	if (cont.length<=0) { nod(); return; } start=millis(); if (RiTa.isQuestion(myRec.resultString)) { askReply(cont); } else { if (sentiment.analyze(myRec.resultString).score>=0) {
			console.log("echo");
			echo(cont);
		} else {
			console.log("yike",sentiment.analyze(myRec.resultString));
			yike(cont);
		}
	}
 
	start=millis();
}
function nod () {
	var arr = ["Alright","Agreeable","Sounds good","Very interesting","I like that."];
	var rand =  round(random(0,arr.length-1));
	myVoice.speak(arr[rand]);
	start=millis();
	imgSwitch("url('./andy/gifs/blink.gif')");
		setTimeout(function(){ imgSwitch("url('./andy/gifs/idle.gif')");}, 800);
}
 
function echo (cont) {
	var rand = -1;
	while (rand<0) {
		rand = round(randomGaussian(0,10))%(cont.length);
	}
	myVoice.speak(cont[rand]);
	imgSwitch("url('./andy/gifs/talk.gif')");
		setTimeout(function(){ imgSwitch("url('./andy/gifs/idle.gif')");}, 800);
}
 
 
function askReply (cont) {
	var arr = ["I don't think I caught that. Try again?","Ah, could you repeat the quetsion?",
				"Sorry, what?","Uh, yes, I think so."];
	var rand = -1;
	while (rand<0) {
		rand = round(random(0,10))%(arr.length+1);
	}
	if (rand==arr.length) {
		myVoice.speak("Um I agree that,"+rm.generateSentence());
	} else {
		myVoice.speak(arr[rand]);
	}
	imgSwitch("url('./andy/gifs/yikes.gif')");
		setTimeout(function(){ imgSwitch("url('./andy/gifs/idle.gif')");}, 800);
}
 
function askThing() {
	var str = "Hey, talk to me about something. How about"+RiTa.randomWord("nn");
	myVoice.speak(str);
	imgSwitch("url('./andy/gifs/talk.gif')");
		setTimeout(function(){ imgSwitch("url('./andy/gifs/idle.gif')");}, 800);
	start = millis();
}
 
function yike(cont) {
	var s = "I.... don't really think I like those vibes you're sending off...";
	myVoice.speak(s);
	imgSwitch("url('./andy/gifs/yikes.gif')");
		setTimeout(function(){ imgSwitch("url('./andy/gifs/idle.gif')");}, 800);
}
 
function imgSwitch(link,pause){
	var canv = document.getElementById("container");//select("#container");
	var orig = canv.style.backgroundImage;
	canv.style.backgroundImage=link;
}
 
function nodOff() {
	imgSwitch("url('./andy/gifs/nodoff.gif')");
	setTimeout(function(){ imgSwitch("url('./andy/gifs/sleep.gif')");}, 800);
}
function wake() {
	myVoice.speak("Sorry,sorry! I kinda fell asleep!");
	imgSwitch("url('./andy/gifs/wake.gif')");
		setTimeout(function(){ imgSwitch("url('./andy/gifs/idle.gif')");}, 900);
}