coqui-ai / STT

🐸STT - The deep learning toolkit for Speech-to-Text. Training and deploying STT models has never been so easy.
https://coqui.ai
Mozilla Public License 2.0
2.27k stars 275 forks source link

Package STT wasm for npm publishing #2265

Closed ccoreilly closed 2 years ago

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

reuben commented 2 years ago
$ ls -lh package/dist
total 320
-r-xr-xr-x@ 1 reuben  staff   155K Oct 26  1985 stt_wasm.js
-r-xr-xr-x@ 1 reuben  staff   2.9K Oct 26  1985 stt_wasm.worker.js
$ ls -lh libstt
total 6920
-rw-r--r--@ 1 reuben  staff    26K Jul 23 14:37 COPYING
-r-xr-xr-x@ 1 reuben  staff   155K Jul 23 14:50 stt_wasm.js
-r-xr-xr-x@ 1 reuben  staff   3.2M Jul 23 14:50 stt_wasm.wasm
-r-xr-xr-x@ 1 reuben  staff   3.0K Jul 23 14:50 stt_wasm.worker.js

Is the ES6 package supposed to be so much smaller than the other one?

ccoreilly commented 2 years ago

No, I forgot to push a change to the Makefile to include the wasm binary. I can do it later.

ccoreilly commented 2 years ago

I added a test step for the wasm npm module but struggled with testing the library itself (it currently only tests that it is installed). I am only familiar with jest, which runs tests inside node and thus ES6 modules need to be transpiled to CommonJS (I tried unsuccessfully to run the ES6 modules with the experimental --experimental-vm-modules flag). Unfortunately, there must be a bug in babel because it adds a space between ! and -- in the following line of the stt_wasm.js:

L1582               if (! --numWorkersToLoad) removeRunDependency("wasm-instantiate");

which breaks the module and does not manage to load successfully. That is why I had to skip the test that actually tests that the library loads and can be used.

I also tried the jsdom environment in jest, which emulates a browser but inside stt_wasm.js the code checks if it is running in node or the browser and it concludes (correctly) that it is running inside node but the emulated environment does not have the expected variables such as __dirname so it crashes.

Maybe someone else can extend the tests in the future (maybe it should be tested with something such as cypress?). As I wrote, for now it only tests that the library is installed and can be imported.

reuben commented 2 years ago

Opened a clone of this PR here to test my fixes.