tesh – Speech
[Warning: mild profanity]
My program was based on the idea of a group voicechat like Skype or Discord, but for all those gamers without friends. It is a groupchat for one person, where all of your friends are computer synthesized voices! You just start up the program and run it while you play some competitive online game, and you can pretend you have friends watching and cheering you on or giving you a hard time if you do poorly. The program responds to your commentary while you are playing the game and react differently based on how you are doing, using your word choice to determine if things are going well or not. If you are doing well and talk about how nice things are going and how the other team is “getting rekt,” your fake friends will cheer you on! But on the flip side, if you start complaining about dying they will take notice of that and gently cyberbully you. If your mic quality isn’t great then your computer comrades can’t hear you and they make comments on that, and sometimes they just have some wisdom they need to bestow upon you that they were reminded of when you said some word. It is about simulating the chaos, interruption, and ridiculousness of a groupchat but now with no external friends required.
Ideally this program works best on a computer, running in the background while you do other things much like in a real voice chat or conference call. I found ways to modify the pitch and rates of speech of the synthesized voices to make them sound more diverse and feel like more people were part of the chat. I also loaded in different dialects of English as well as some non-English voices.
The program latches onto keywords for positivity, or “hyping,” negativity, or “mocking,” and the other 2 modes, mishearing and spouting non-sequiturs, is based off of any random word you say that does not meet the first 2 categories. To create the non-sequiturs I loaded in a text file full of one-liners (from this website) and then created Markov chains based off of those, finally subbing in a word from the newly created one-liner with something the user said to add relevancy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | // The speech recognizer var mySpeechRecognizer; var mostRecentSpokenWord; var mostRecentConfidence; var mostRecentPhrase = []; var lastTwoWords = ["1", "2"]; var responseArray = []; var textSource = []; var txt = ""; rm = new RiMarkov(4, true, false); var xshift = 25; var yshift = 20; // The speech synthesizer var myVoiceSynthesizer; var myVoiceNames = ["Microsoft David Desktop - English (United States)", "Microsoft Zira Desktop - English (United States)", "Google US English", "Google UK English Female", "Google UK English Male", "Google Nederlands", "Google Deustch"]; // The RiTa Lexicon var myRitaLexicon; var bFoundRhymeWithMostRecentWord = true; var bWord = true; var aWordThatRhymesWithMostRecentWord = ""; var arrayOfRhymingWords = []; var confidenceThresh = 0.3; var mishearChance = 0.75; var nonSeqChance = 0.7; var responsePhrase = ""; //Prompts? var mockArray = ["fuc", "fuk","f***", "f******", "s***", "sniped", "ouch", "oh", "impossible", "died"]; var hypeArray = ["nice", "sick", "sweet", "rad", "yes", "yeah"]; var hypeArray2 = ["I won", "we won", "we win", "sniped them", "did it", "get wrecked", "get rekt", "pretty good"]; //Responses var mockResponseArray = ["you sure did it.", "lol, get rekt!", "scrub", "what, was that.", "delete your account", "time for a different game?", "I've never seen something so terrible."]; var hypeResponseArray = ["hell yes", "nice!", "sweet", "heck yeah", "woah!", "nice job!", "not the best I've seen but definitely not the worst", "pretty damn good!", "great job!", "kickass!"]; var nonseqArray = ["You know what they say,", "Oh that reminds me of how", "Like they always say,", "lol, like I always say,"]; var mishearArray = ["you do what with ", "you what your what?", "what did you just say to me?", "I think your microphones busted.", "you're cutting out!"]; //========================================= function preload() { textSource = loadStrings('/addons/1liners.txt'); } //========================================= function setup() { createCanvas(520, 520); // Make the speech recognizer txt = join(textSource, '\n'); rm.loadText(txt); mostRecentConfidence = 0; mostRecentSpokenWord = ""; initializeMySpeechRecognizer(); // Make the speech synthesizer myVoiceSynthesizer = new p5.Speech(); myVoiceSynthesizer.setVoice(random[myVoiceNames]); myVoiceSynthesizer.interrupt=true; // 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(27); // Draw detected speech: fill(65); rect(xshift,yshift, width-(xshift*2),yshift+40); rect(xshift,yshift+70, width-(xshift*2),height-yshift*5.5); fill(180,215,240); textFont("Century Gothic"); textSize(18); textAlign(LEFT); text("You entered the lobby..." , xshift+5, yshift*2); if(mySpeechRecognizer.resultString != undefined && mySpeechRecognizer.resultString.length <= 50){ text("You said: \"" + mySpeechRecognizer.resultString + "\"", xshift+5, yshift*3+10); } else{ text("Say Something! ", xshift+5, yshift*3+10); } //findRhymeWithMostRecentWord(); wordCheck(); //print(hypeCheck()); myVoiceSynthesizer.setRate(random(1.05,1.15)); myVoiceSynthesizer.setPitch(random(0.5,1.45)); myVoiceSynthesizer.setVoice(random(myVoiceNames)); fill(51,139,213); for(i=0;i<responseArray.length;i++){ text(responseArray[i], xshift+20, 110+(25*i)); } if(millis()%5000 >= 0 && millis()%5000 < 10){ initializeMySpeechRecognizer(); } } //========================================= 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(); } if (key === 'M'){ var sentences = rm.generateSentence(); var rSentences = new RiString(sentences); var sentenceWords = rSentences.words(); var sentencePos = rSentences.pos(); var nonSeqWord = random(mostRecentPhrase); var wordSwap = new RiString(nonSeqWord); var pos = wordSwap.pos(); for(i=0;i <sentenceWords.length; i++){ if (sentencePos[i] == pos[0]){ sentenceWords[i] = nonSeqWord; break; } } print(RiTa.untokenize(sentenceWords)); bWord = false; wordCheck(); myVoiceSynthesizer.setRate(random(1.05,1.15)); myVoiceSynthesizer.setPitch(random(0.5,1.45)); myVoiceSynthesizer.setVoice(random(myVoiceNames)); } } //========================================= function parseResult() { mostRecentConfidence = mySpeechRecognizer.resultConfidence; lastTwoWords[1] = "1"; lastTwoWords[2] = "2"; if (mostRecentConfidence > confidenceThresh){ // 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: mostRecentSpokenWord = mySpeechRecognizer.resultString.split(' ').pop(); mostRecentPhrase = mySpeechRecognizer.resultString; mostRecentPhrase = RiTa.tokenize(mostRecentPhrase); print(mostRecentPhrase); print(mostRecentConfidence); if (mostRecentPhrase.length >= 2){ lastTwoWords[1] = mostRecentPhrase[mostRecentPhrase.length-2]; lastTwoWords[2] = mostRecentPhrase[mostRecentPhrase.length-1]; } else if(mostRecentPhrase.length == 1){ lastTwoWords[1] = "1"; lastTwoWords[2] = mostRecentPhrase[mostRecentPhrase.length-1]; } else{ lastTwoWords[1] = "1"; lastTwoWords[2] = "2"; } bWord = false; } } //========================================= function wordCheck(){ if(bWord == false){ responsePhrase = ""; if(mostRecentConfidence > confidenceThresh && mostRecentConfidence < 0.7){ //Say statement from response array template responsePhrase = mishearArray[int(random(1,mishearArray.length-1))]; } else if(lastTwoWords[2] != "2"){ //check if should be hyping if(hypeCheck() == true){ hype(); } //check if should be mocking else if(mockCheck() == true){ mock(); } else if(random(1) > nonSeqChance){ nonSeq(); } else if(random(1) > mishearChance){ mishearWord(); } } bWord = true; if (responsePhrase != ""){ updateTexts() myVoiceSynthesizer.speak(responsePhrase); } } } function mishearWord(){ var similarWord=""; var mishearNum = int(random(0,mishearArray.length)); // if at least 1 word // generate similar word or keep original similarWord = lastTwoWords[2]; if(random(1)<0.75){ similarWord = RiTa.similarBySound(lastTwoWords[2]); similarWord = similarWord[int(random(0,similarWord.length))]; } // Say word along with statement from array if(random(1) > 0.5){ responsePhrase = ("What? "+similarWord+"??"); } else{ if (mishearNum > 2){ responsePhrase = (similarWord+"?? "+mishearArray[mishearNum]); } else{ responsePhrase = (mishearArray[mishearNum]+" "+similarWord+"??"); } } } function hype(){ var hypeRand = random(1); if(hypeRand > .6){ responsePhrase = (random(hypeArray) +"! "+ random(hypeResponseArray)+"!"); } else if(hypeRand > .3){ responsePhrase = (random(hypeArray2) +"! "+ random(hypeResponseArray)+"!"); } else{ responsePhrase = random(hypeResponseArray); } } function hypeCheck(){ if(lastTwoWords[1]!= "1"){ for(i=0;i<hypeArray2.length;i++){ if((lastTwoWords[1]+" "+lastTwoWords[2]) == hypeArray2[i]){ print(lastTwoWords[1]+" "+lastTwoWords[2]); return true } } } for(i=0;i<hypeArray.length;i++){ if(lastTwoWords[2] == hypeArray[i]){ return true } } return false } function mock(){ responsePhrase = (random(mockResponseArray)); } function mockCheck(){ for(i=0;i<mockArray.length;i++){ if(lastTwoWords[2] == mockArray[i]){ return true } } return false } function nonSeq() { var sentences = rm.generateSentence(); var rSentences = new RiString(sentences); var sentenceWords = rSentences.words(); var sentencePos = rSentences.pos(); var nonSeqWord = random(mostRecentPhrase); var wordSwap = new RiString(nonSeqWord); var pos = wordSwap.pos(); var newSent = ""; for(i=0;i <sentenceWords.length; i++){ if (sentencePos[i] == pos[0]){ sentenceWords[i] = nonSeqWord; responsePhrase = (random(nonseqArray)+" \n"+RiTa.untokenize(sentenceWords)); break; } if(i==sentenceWords.length-1){ responsePhrase = ""; } } } function updateTexts(){ if(responseArray.length > 14){ responseArray.shift() } responseArray.push(responsePhrase); if(responsePhrase.length>45){ responseArray.push(""); if(responseArray.length > 14){ responseArray.shift() } } } |