IDMNYU / p5.js-speech

Web Audio Speech Synthesis / Recognition for p5.js
MIT License
261 stars 112 forks source link

picking random voice example #13

Closed shiffman closed 6 years ago

shiffman commented 6 years ago

Hi @rev3rend, thanks again for helping me understand the library this morning. I have one example where I want to pick a random new voice, so I am not setting a voice initially but I do want a callback for when the voices are available, i.e.:

speech = new p5.Speech(voiceReady);
function voiceReady() {
  let voice = random(speech.voices);
  speech.setVoice(voice.name);
  speech.speak('Hello');
}

How do you feel about adding this extra one line check for the p5.Speech constructor?

if (_dv !== undefined && typeof _dv == 'function') this.onLoad = _callback; // NEW!
else if (_dv !== undefined) this.initvoice = _dv;
if (_callback !== undefined) this.onLoad = _callback;

Alternatively I can just write my code like so which is ok too:

  speech = new p5.Speech();
  speech.onLoad = voiceReady;

Let me know which you prefer and I can adjust my example or submit a pull request with just the one line.

simon-tiger commented 6 years ago

It actually was _dv instanceof Function before, but I sead it's actually typeof.

simon-tiger commented 6 years ago

Dan has got another example using p5.SpeechRec:

speechRec = new p5.SpeechRec(gotSpeech);
let continuous = true;
let interimResults = false;
speechRec.start(continuous, interimResults);
function gotSpeech(speech) {
  console.log(speech);
  if (speech.success) {
    createP(speech.text);
  }
}

, And it's got the same problem.

shiffman commented 6 years ago

I sorted this out and will just use the API as is, thanks for your patience!