evancohen / sonus

:speech_balloon: /so.nus/ STT (speech to text) for Node with offline hotword detection
MIT License
618 stars 79 forks source link

Sonus.pause(sonus) and Sonus.resume(sonus) #95

Open ginixsan opened 5 years ago

ginixsan commented 5 years ago

I've read previous issues but haven't been able to get anything clear.When I try to pause or resume sonus with Sonus.pause(sonus). I get this error.

Sonus.pause = () => record.pause() ^

TypeError: record.pause is not a function

I've tried too stoping it and restarting it but then I get the

throw er; // Unhandled 'error' event ^

Error: write after end

That I saw some people get too. Anybody was able to get any workaround to pause sonus and resume it?

evancohen commented 5 years ago

Just took a quick look at this, looks like this is a bug that was introduced in the most recent version. I'll take a stab at fixing it this weekend and publishing a fix. Thanks for reporting this!

ZTiKnl commented 4 years ago
(node:3503) UnhandledPromiseRejectionWarning: TypeError: record.pause is not a function
    at Writable.sonus.pause (/home/ztik/nodejs/sara/node_modules/sonus/index.js:141:12)

Seems like it is still ongoing (for me at least)...

A solution/workaround would be appreciated, but personally I am not in any hurry ;)

evancohen commented 4 years ago

Oof, this fell off my radar, sorry! Will attempt to fix asap.

ZTiKnl commented 4 years ago

No need to apologize, instead I should say thanks for this wonderful module. It is a core function of my app, without it I'd have no app at all ;) (I also included a link to sonus in the credits of my app)

P.S. feel free to ask for more information if you need any

evancohen commented 4 years ago

Immediate solution is to comment out https://github.com/evancohen/sonus/blob/master/index.js#L140-L146 in your node_modules folder. It seems that at some point pause and resume was removed from the underlying audio library.

They just pushed a new version of that library that supports this functionality, so I'm going to go ahead and update everything to use that instead.

evancohen commented 4 years ago

So I have a working version with the new recording library, but it didn't match well with the current implementation. I'm not thrilled with the results. I'm going to do a refactor, but I've pushed the changes as-is to the pause-resume branch and published a release candidate on npm: sonus@1.0.4-rc1

To use this version just

npm install sonus@next
ZTiKnl commented 4 years ago

I have just ran npm uninstall sonus and npm install sonus@next. package.json seems to confirm this:

  "dependencies": {
    "sonus": "^1.0.4-rc1",

However, I am still receiving the same error as before:

(node:3436) UnhandledPromiseRejectionWarning: TypeError: record.pause is not a function
    at Object.Sonus.pause (/home/ztik/nodejs/sara/node_modules/sonus/index.js:204:28)
    at Object.pause (/home/ztik/nodejs/sara/hearing.js:63:11)

Is it possible that some dependency requires separate updating? (I'm new to javascript/nodejs, so it is quite possible that I'm wrong/misunderstanding)

edit: package.json in ./node_modules/sonus also tells me I'm using rc1: "version": "1.0.4-rc1"

ncpleslie commented 4 years ago

Any update on this?

It seems that the "node-record-lpcm16" version used by Sonus ("^0.3.1") doesn't support Pause/Resume until version "1.0.0". Attempted to rectify the issue by using "npm install sonus@next" but was unsuccessful.

evancohen commented 4 years ago

I won't be able to look at this until over the holidays, but hopefully I can figure something out on vacation next week.

ncpleslie commented 4 years ago

I gave it a go and managed to have some success. I tested it on a Raspberry Pi and it seemed to be working.

https://github.com/ncpleslie/sonus

simon-tannai commented 4 years ago

Hi ! I'm trying to use .pause() and .resume() but I got this error: INVALID_INDEX.

sdetweil commented 3 years ago

I've created a socket.io mechanism to talk the background sonus process to allow it to reliquish the microphone. also added mechanism to use the existing plugins the get audio back from secondary recording

for alex and google assistant, think of the multi-turn dialog for creating a calendar entry