syl22-00 / pocketsphinx.js

Speech recognition in JavaScript and WebAssembly
1.49k stars 261 forks source link

Wasm decoding failed #120

Open jjenzz opened 6 years ago

jjenzz commented 6 years ago

I am trying to get this up and running and I'm getting the following error:

CompileError: AsyncCompile: Wasm decoding failed: expected magic word 00 61 73 6d, found 3c 21 44 4f @+0

The only code I have atm is:

this.recognizer = new Worker('js/recognizer.js');
this.recognizer.onmessage = this.handleReady; // this method is empty atm
this.recognizer.postMessage({});

All files from the webapp/js directory are in my public js directory.

Any idea where I am going wrong?

syl22-00 commented 6 years ago

I believe that means pocketsphinx.wasm was not found. You can set the location in your postMessage call: this.recognizer.postMessage({'pocketsphinx.wasm': 'path/to/pocketsphinx.wasm'});.

jjenzz commented 6 years ago

@syl22-00 I'm not sure that is the issue because the following suggests it found something in the wasm file that it wasn't expecting:

expected magic word 00 61 73 6d, found 3c 21 44 4f @+0

Furthermore:

image

image

syl22-00 commented 6 years ago

This is indeed strange, is it a file that you compiled yourself? It does not have the correct header and is only 1.2KB big. The file in the repo is 467kB big.

Venryx commented 5 years ago

Got this same error for the opus-media-recorder library. (this is the only result on the internet for the given "expected magic word..." error message!)

For me, the problem was that I was using the following:

app.use(require("connect-history-api-fallback")({
    rewrites: [
        {
            from: /^(.(?!\.(html|js|css|png|jpg)))+$/, // paths with these extensions will NOT be redirected to "index.html""
            to(context) {
                return "/index.html";
            },
        },
    ],
}));

Notice that it's rewriting any url's that don't end in the special resource-extensions (html, js, etc.) with the url for the homepage. The problem is that I forgot to add .wasm to that list, meaning that when the browser requested the .wasm files, it was receiving the index.html file instead.

Adding .wasm to that list resolved the issue.

jackbilestech commented 4 years ago

3c 21 44 4f @+0 in ascii is <!DO whihc is the header of a HTML file. So the file you're trying to load is not found in the path given. You'll have to statically deploy the relevant files first in order for the HTTP request to be made.