stephenlb / spoken

Spoken - JavaScript Text-to-Speech and Speech-to-Text for AI Artificial Intelligence Apps
https://stephenlb.github.io/spoken/
70 stars 11 forks source link

Unexpected ending of recording during document recording #8

Closed pgoodbread closed 4 years ago

pgoodbread commented 4 years ago

Hi Stephen,

thanks for your great work on this package.

I'm using it to write documents via dictation. I have encountered the problem, that after a while the spoken.listen() function seems to automatically stop. No error is thrown.

It really hinders me during dictation.

Do you have any idea why this happens?

stephenlb commented 4 years ago

There is a time limit. You can get around the time limit like this: https://github.com/stephenlb/spoken#continuous-listening-example

Screen Shot 2020-06-05 at 3 40 50 PM
pgoodbread commented 4 years ago

Sorry about being not precise enough.

I'm using the library within a vue project and have enabled continuous listening mode.

methods: {
    startListening() {
      spoken.listen.on.end(this.continueCapture);
      spoken.listen.on.error(this.continueCapture);

      spoken.listen({ continuous : true })
      .then( transcript => {
        this.listenedText = this.listenedText + transcript
      })
      .catch( e => {console.warn(e.message), true } );
    }, 
    stopListening() { 
      spoken.recognition.continuous = false;
      spoken.listen.stop();
      this.startedListening = false
    }, 
    async continueCapture() {
      await spoken.delay(300);
      if (spoken.recognition.continuous) this.startListening();
    }
  },
  mounted() {
    spoken.listen.on.end(this.continueCapture);
    spoken.listen.on.error(this.continueCapture);
  }

Yet, after a while it just stops listening. Do you have any suggestions? I coul try a plain html file with javascript.

stephenlb commented 4 years ago

What you suggest may be a good next step. For reference, we have a production live website that is using continuous successfully here:

This reference example demonstrates a successful implementation of the continuous listening feature.

pgoodbread commented 4 years ago

Hello Stephen,

thank you for your input.

I tried implementing it based on the source code file you suggested, but it still stops for me after a while. I have discovered that it's often after like 2:30min. On the other hand it seems like it has some kind of hiccup if I speak unclearly, or my recording quality is too bad. It suddenly stops and never starts again.

I tried another implementation, dead simple, independently from VueJS. Still having similar problems.

Here is my source code - for any help and suggestions I would be super grateful.

require('spoken');

document.addEventListener('DOMContentLoaded', () => {

  spoken.recognition.lang = 'de-DE';

  // Listen to Microphone
  if (mic == 'off') return;

  console.log("loaded")

  document.getElementById("start").addEventListener('click', () => {
    spoken.listen.on.end(listen);
    spoken.listen.on.error(listen);
    spoken.listen.on.partial(ts => console.log(ts));
    delay(200);
    listen();
  })

  document.getElementById("stop").addEventListener('click', () => {
        spoken.listen.on.end(() => {});
        spoken.listen.on.error(() => {});
        delay(500);
    stopCapture();
  })
})

  async function listen() {
    console.log('listen start')
    await delay(200);
    await spoken
    .listen({ continuous: true })
    .then(ts => console.log('end of listen => ', ts))
    .catch((e) => console.log(e));
  }

  function delay(duration) {
    return new Promise((resolve) => setTimeout(resolve, duration));
  }

function stopCapture() {
  console.log('stopCapture beginning')
  spoken.recognition.continuous = false;
  spoken.listen.stop();
  console.log('stopCapture end')
}

function writeText(text) {
  document.getElementById('text').innerText = text
}
stephenlb commented 4 years ago
  1. For stopCapture() you should only need to execute spoken.listen.stop(); no need to change the continuous setting.
  2. The delay() calls in each addEventListener are not really doing anything. Okay to remove those.
  3. The big issue is that you're not using the candidate partial data updates. Make sure you are suing the candidates.
spoken.listen({continuous:true}).then( speech => {
    candidate(speech); // <--- UPDATE UI with speech
} ).catch( e => true );
spoken.listen.on.partial(candidate);
pgoodbread commented 4 years ago

Thank you @stephenlb!

I got it to work and therefore will close this issue.