A library that provides simple, clear access to the Web Speech and Speech Recognition APIs, allowing for the easy creation of sketches that can talk and listen.
See Synthesis Example and
Recognition Example
“thyme” by ookey
https://openprocessing.org/sketch/512691
License CreativeCommons Attribution ShareAlike
https://creativecommons.org/licenses/by-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
speak a word, any key to refresh
CC Attribution ShareAlike
thyme
xxxxxxxxxx
// 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;
}
See Synthesis Example and Recognition Example
Example
See More Shortcuts