samedi 4 août 2018

Javascript: Speech recognition on an iphone

I am a total noob here so please forgive me if I am asking a stupid basic question.

I have been trying to use a speech recognition plugin to get speech to text on a webpage that is viewed in safari on an iphone.

However, after spending ages trying to figure it out I came across this: https://caniuse.com/#feat=speech-recognition which just shot me completely in the foot.

I then came across this JSFiddle which seems to work on the browser but when I view it on my phone nothing happens.

Code form fiddle as it said I need to include it:

var player = document.getElementById('player');

var handleSuccess = function(stream) {
  if (window.URL) {
    player.src = window.URL.createObjectURL(stream);
  } else {
    player.src = stream;
  }
};

navigator.mediaDevices.getUserMedia({ audio: true, video: false })
    .then(handleSuccess);

  var handleSuccess = function(stream) {
  var context = new AudioContext();
  var source = context.createMediaStreamSource(stream);
  var processor = context.createScriptProcessor(1024, 1, 1);

  source.connect(processor);
  processor.connect(context.destination);

  processor.onaudioprocess = function(e) {
    // Do something with the data, i.e Convert this to WAV
    console.log(e.inputBuffer);
  };
};

navigator.mediaDevices.getUserMedia({ audio: true, video: false })
    .then(handleSuccess);

I keep reading in various older posts that this is not possible on mobile devices but I can't believe that, now with everything we can do there is no way to do this? That seems a little insane. Someone pointed out that not even google have it on their web translate for phones.

So, I turn to you guys. Is there a way to record my voice in my web app on my iPhone/Android device and then for example send that to the amazon polly api or bing translate api?

Thanks




Aucun commentaire:

Enregistrer un commentaire