0

I am trying to start the speech input session without clicking on the microphone icon. Like on window load or document load event - Instead of default click event.

<input type="text" id="autoStart" x-webkit-speech />

I am using google chrome as it supports most of the HTML 5 features.

Rohit Sharma
  • 13
  • 1
  • 4
  • 3
    I may be wrong, but I'm pretty sure if this would be possible it would be considered a privacy issue. – starbugs Apr 26 '12 at 15:47
  • Yes, recording somebodys speech without permission should be a security issue, but nevertheless I want to achieve this task in order to start my project. Thanks for chipping in. – Rohit Sharma Apr 26 '12 at 15:53
  • possible duplicate of [Automate speech input recording in Chrome](http://stackoverflow.com/questions/7751146/automate-speech-input-recording-in-chrome) – Shoban Apr 30 '12 at 14:27

1 Answers1

0

Execute this code on page load and you'll see a permissions dialogue asking you to grant microphone access. Click allow and speech to text recognition will begin. Check the speech recognition API docs for events you can bind to.

var interim_result, final_result;
var recognition_engine = new webkitSpeechRecognition();

recognition_engine.continuous = true;
recognition_engine.interimResults = true;
recognition_engine.lang = 'en-US';
recognition_engine.onresult = function(function(e) {

  var result, i;

  interim_result = '';
  if (typeof e.results === 'undefined') {

    recognition_engine.stop();
    console.log('SPEECH RECOGNITION : stopping due to empty result.', e);
    return;
  }
  for (i = event.resultIndex; i < event.results.length; ++i) {
    result = event.results[i];
    if (result.isFinal) {
      final_result = result[0].transcript;
      console.log('SPEECH RECOGNITION : final transcript = ' + final_result, e);
      // trigger a command matching the final utterance here
    } else {
      interim_result += result[0].transcript;
    }
  }
  console.log('SPEECH RECOGNITION : interim result = ' + interim_result);
};
recognition_engine.start();
atomless
  • 1,272
  • 15
  • 18