Discord.js: Implement a performant alternative to node-opus

Created on 12 Jan 2020  路  8Comments  路  Source: discordjs/discord.js

Is your feature request related to a problem? Please describe.
node-opus keeps breaking on every other Node.js release due to V8 API changes

Describe the ideal solution
Provide a native alternative for node-opus on top of N-API. I don't expect this to be a difficult task - the (raw) API node-opus provides follows the libopus API closely and the native bits are a very thin wrapper around that API to make it available to JS.

Describe alternatives you've considered
None

Additional context
I'm getting a bit tired of keeping node-opus up to date with the ever changing V8 APIs. Currently I have no intention in making node-opus compatible with the latest Node version (12.x?). It feels like 90%+ of its users are discord bots, so I felt like giving this project a heads up.

dependencies voice enhancement

Most helpful comment

Thank you for your efforts @Rantanen!

I took the task and rewrote it here: https://github.com/discordjs/opus

Since I based this off your code (not that there was a lot, like you said its a very thin wrapper to begin with) I made sure to put you into the copyright notice.

All 8 comments

It was brought to our attention that opusscript provides an option to run WebAssembly instead of JavaScript to boost all operations, however, we have not benchmarked this.

Are you able to uninstall node-opus and try opusscript (wasm mode is enabled by default), then check if it works and compare it to node-opus in a supported version? Having some metrics about how Wasm performs versus C++ Addons would be interesting.

Are you able to uninstall node-opus and try opusscript (wasm mode is enabled by default),

No, sorry. I wouldn't know where to start. I'm not really a user of discord.js.

Just wanted to notify you that node-opus might not be that great of a long term solution anymore.

Thanks for the heads up @Rantanen. Also a thanks from us and our community for node-opus, it's been massively useful to our users over the years :)

Regarding the benchmarks, I ran a rough one and found that to process a 3 minute 20 seconds audio file:

  • node-opus takes about 2 seconds
  • opusscript (wasm) takes about 4 seconds
  • opusscript (no wasm) takes about 24 seconds

I think for most users, using opusscript instead of node-opus will be perfectly fine for the time being! You can get the wasm version of opusscript by just making sure you are using at least Node 8 and have the latest opusscript installed :+1:

Good to hear! I'm sure the wasm version is easier to maintain and breaks less often too!

@Rantanen if V8 breakage is the problem, you might want to look at n-api. it's ABI stable across all versions of node that have it. There is also a C++ wrapper available.

@devsnek Yeah, that would be a solution, like mentioned in the original issue. Unfortunately I don't really have interest in putting that effort into node-opus anymore. :(

I feel like the NodeJS community would be better served by an Opus implementation that has an author who actually wants to provide a good NodeJS Opus implementation instead of one that just wants open GitHub issues to go away. :)

Thank you for your efforts @Rantanen!

I took the task and rewrote it here: https://github.com/discordjs/opus

Since I based this off your code (not that there was a lot, like you said its a very thin wrapper to begin with) I made sure to put you into the copyright notice.

Took me this long to finally do it but it's official now. The Rantanen/node-opus repository has been archived, the npm package has been deprecated and it's directing people to use @discordjs/opus instead.

Thanks @iCrawl for implementing the N-API alternative! :heart:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tiritto picture tiritto  路  3Comments

iCrawl picture iCrawl  路  3Comments

kvn1351 picture kvn1351  路  3Comments

Acaretia picture Acaretia  路  3Comments

LLamaFTL picture LLamaFTL  路  3Comments