xxxxxxxxxx
55
let video;
let poseNet;
let poses = [];
let speechRecognition = new webkitSpeechRecognition();
let words = [];
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.size(width, height);
poseNet = ml5.poseNet(video, modelReady);
poseNet.on('pose', function(results) {
poses = results;
});
video.hide();
speechRecognition.continuous = true;
speechRecognition.interimResults = true;
speechRecognition.onresult = gotSpeech;
speechRecognition.start();
}
function draw() {
image(video, 0, 0, width, height);
if (poses.length > 0) {
let pose = poses[0].pose;
let keypoint = pose.keypoints[0]; // nose
if (keypoint.score > 0.2) {
fill(255, 0, 0);
noStroke();
ellipse(keypoint.position.x, keypoint.position.y, 10, 10);
for (let i = 0; i < words.length; i++) {
fill(255);
textSize(random(10, 24));
text(words[i], keypoint.position.x + random(-100, 100), keypoint.position.y + random(-100, 100));
}
}
}
}
function gotSpeech(event) {
let latest = event.results[event.results.length - 1];
if (latest.isFinal) {
words = latest[0].transcript.split(' ');
}
}
function modelReady() {
select('#status').html('Model Loaded');
}