xxxxxxxxxx
let speech;
let input = "...";
let bg;
let table;
let out;
let c = 1;
let textbox;
function setup() {
//createCanvas(1080, 1920);
background(250);
//speech = new p5.SpeechRec('de-DE'); // speech recognition object (will prompt for mic access)
// de-DE; en-EN
speech = new p5.SpeechRec('de-DE');
speech.onResult = showResult; // bind callback function to trigger when speech is recognized
speech.onError = onError;
speech.onEnd = onEnd;
speech.continuous = true; // do continuous recognition
//speech.interimResults = true;
speech.start(); // start listening
textAlign(CENTER, CENTER);
textSize(200);
table = new p5.Table();
table.addColumn('time');
table.addColumn('text');
createCanvas(windowWidth, windowHeight);
textbox = createElement('textarea'); //createInput();
textbox.position(20, 20);
textbox.size(300, height-40);
//frameRate(1)
//bg = color(255);
}
function draw() {
let newRow = table.addRow();
newRow.setString('time', Date());
newRow.setString('text', input);
//background(255, 0, 0);
//text(input, 20, c*20);
//ellipse(500,500, 5,5);
//c++;
//input = "...";
if (c*20>1000){
background(250);
c = 1;
}
textbox.value(input);
}
function showResult()
{
// no interim results (phrases with delay, but accurate)
//input += speech.resultString;
let words = speech.resultString.split(' ');
for (let i=0; i<words.length; i++) {
input += int(millis()/1000) + ": " + words[i] + " (" + speech.resultConfidence + ")\n";
}
//var mostrecentword = speech.resultString.split(' ').pop();
//input += " " + mostrecentword;
//textbox.value(input);
//speech.start();
//out += input;
}
function keyPressed() {
if (key == "c") {
save(table, 'Transcript.csv');
}
}
function onError() {
input += int(millis()/1000) + ": error\n";
speech.start();
}
function onEnd() {
input += int(millis()/1000) + ": end\n";
speech.start();
}