(p5.dom is now part of p5js, no need to enable if using v0.10+). p5.dom library lets you use video, audio, webcam, input, and text.
Examples: Dom - Video
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
“Wikinfomation” by TyVan
https://openprocessing.org/sketch/513454
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!
CC Attribution ShareAlike
Wikinfomation
xxxxxxxxxx
// A program that says a word which rhymes
// with the most recent word you said.
// The speech recognizer
var mySpeechRecognizer;
var mostRecentSpokenWord;
var mostRecentConfidence;
// The speech synthesizer
var myVoiceSynthesizer;
// The RiTa Lexicon
var myRitaLexicon;
var bFoundRhymeWithMostRecentWord = true;
var aWordThatRhymesWithMostRecentWord = "";
var arrayOfRhymingWords = [];
let searchUrl = 'https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=';
let contentUrl = 'https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=';
let userInput;
let counter = 0;
//=========================================
function setup() {
createCanvas(800, 800);
// Make the speech recognizer
mostRecentConfidence = 0;
mostRecentSpokenWord = "";
initializeMySpeechRecognizer();
// Make the speech synthesizer
myVoiceSynthesizer = new p5.Speech();
myVoiceSynthesizer.setVoice(0);
// 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);
}
// Press Space to Reset
//=========================================
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();
}
}
// Confidence Threshold
//=========================================
function parseResult() {
mostRecentConfidence = mySpeechRecognizer.resultConfidence;
if (mostRecentConfidence > 0.5){ // 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();
bFoundRhymeWithMostRecentWord = false;
}
findRhymeWithMostRecentWord();
}
//=========================================
function findRhymeWithMostRecentWord(){
if ((bFoundRhymeWithMostRecentWord === false) &&
(mostRecentSpokenWord.length > 0)){
// Ask RiTa which words rhyme with mostRecentSpokenWord
var rhymes = myRitaLexicon.rhymes(mostRecentSpokenWord);
// If there are any words that rhyme,
var nRhymes = rhymes.length;
if (nRhymes > 0){
// Select a random one from the returned list, and speak it.
aWordThatRhymesWithMostRecentWord = rhymes[floor(random(nRhymes))];
myVoiceSynthesizer.speak( aWordThatRhymesWithMostRecentWord);
// Keep the first 10 rhyming words; insert some newline characters
var arr = subset(rhymes, 0, min(nRhymes, 10)); // max of 10 words
arrayOfRhymingWords= arr;
console.log(arrayOfRhymingWords);
} else {
// But if there are no rhymes, blank it.
aWordThatRhymesWithMostRecentWord = "";
arrayOfRhymingWords = [];
}
bFoundRhymeWithMostRecentWord = true;
}
WIKI();
}
function WIKI(){
readThruRhymes();
function readThruRhymes(){
for(i=0; i< arrayOfRhymingWords.length; i++){
console.log(arrayOfRhymingWords);
gotSearch(arrayOfRhymingWords[i])
}
}
function gotSearch(data) {
let title = data;
title = title.replace(/\s+/g, '_');
createDiv(title);
console.log('Querying: ' + title);
let url = contentUrl + title;
console.log(title);
displayWikiPages(title);
doIt(title);
}
function displayWikiPages(title){
var xPos = int(random(50, 800));
var yPos = int(random(50, 800));
var wid = int(random(0, 1000));
var hght = int(random(0, 1000));
translate(100,100);
var yo = createDiv( '<iframe src="https://en.wikipedia.org/wiki/' + title + '" width=' + wid + ' height=' + hght + ' scrolling="yes" frameboarder=0></iframe>' );
yo.position(wid, hght);
}
}
// Daniel Shiffman
// http://codingtra.in
// http://patreon.com/codingtrain
// Wikipedia
// Edited Video: https://youtu.be/RPz75gcHj18
function doIt(word) {
let counter = 0;
goWiki(word);
function goWiki(term) {
counter = counter + 1;
if (counter < 10) {
//let term = userInput.value();
let url = searchUrl + term;
loadJSON(url, gotSearch, 'jsonp');
}
}
function gotSearch(data) {
console.log(data);
let len = data[1].length;
let index = floor(random(len));
let title = data[1][index];
title = title.replace(/\s+/g, '_');
createDiv(title);
console.log('Querying: ' + title);
let url = contentUrl + title;
loadJSON(url, gotContent, 'jsonp');
}
function gotContent(data) {
let page = data.query.pages;
let pageId = Object.keys(data.query.pages)[0];
console.log(pageId);
let content = page[pageId].revisions[0]['*'];
console.log(content);
myVoiceSynthesizer.speak( content);
let wordRegex = /\b\w{4,}\b/g;
let words = content.match(wordRegex);
let word = random(words);
goWiki(word);
console.log(word);
}
}
Examples: Play - Synthesis - Microphone
p5.dom library lets you use video, audio, webcam, input, and text.
Examples: Dom - Video
See Synthesis Example and Recognition Example
Example
See More Shortcuts