Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make hark detect silence after a pause of 1.5 secs or 2 secs? #42

Open
Ayushimidha28 opened this issue Jun 15, 2020 · 1 comment

Comments

@Ayushimidha28
Copy link

I have tried using setInterval() function and options.interval but it's not working.

@dongido001
Copy link

dongido001 commented Aug 23, 2020

You can do that from your own code...

For example, I want to listen for silence after 2 seconds...

import * as moment from "moment"

let speaking, 
     silence, 
     timerCount, 
    timeCountInterval, 
    silenceTime = null
const SILENCE_TIME = 2 * 1000 // 2 sec

hark.on("speaking", () => {
    speaking = true
})

hark.on("stoped_speaking", () => {
   if (!silenceTime) {
       silenceTime = moment().unix()
   }

    setTimeInterval(() => {
       if (speaking === true &&
          silenceTime &&
          moment().unix() - silenceTime >= SILENCE_TIME) {
             // Do what ever you want to do here, we know they are now silence
             speaking = false
             clearInterval(timeCountInterval)
      }
    }, 1000) // run every 1 sec
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants