msqr1 / Vosklet

A speech recognizer that can run on the browser, inspired by vosk-browser
MIT License
33 stars 1 forks source link

"TypeError: cannot convert undefined to object" in VoskletTransferer #7

Closed tdcook closed 5 months ago

tdcook commented 5 months ago

Sometimes, VoskletTransferer will throw a TypeError: cannot convert undefined to object exception immediately after initialization. It won't always happen right away, but usually will after a few reloads. It seems there is a race condition between the connection of the source and processor nodes and the execution of VoskletTransferer's process method.

The error is being thrown here:

https://github.com/msqr1/Vosklet/blob/76aedbdfee862de8a734a3a4f09ffb82eeaf50da/src/wrapper.js#L11

Adding a falsiness check here should fix it:

const data = inputs[0][0]
if (!data) return true
this.buffer.set(data, this.count * 128)
msqr1 commented 5 months ago

Ngl, I never encounter this issue when testing (where I reload a zillion times). What browser are you using?

Thanks for pointing this out, I'll fix it ASAP!

tdcook commented 5 months ago

I have tried Chrome and Firefox, all on a Linux machine with a USB microphone attached. I suspect it only crops up on certain systems.

msqr1 commented 5 months ago

Can you try unplugging the USB microphone, if you are encountering issue from the microphone recognition? Or is it just straight from startup, not doing anything yet?

tdcook commented 5 months ago

It happens right on startup, before any recognition starts. I have only seen it happen there, never after a successful startup.

msqr1 commented 5 months ago

This path of code is quite hot, can you try unplugging the USB microphone to see? I tried many times to see if it would pop up, but it wouldn't. Can you try if the USB microphone was the problem? Maybe it messed with the AudioContext?

tdcook commented 5 months ago

Well, if I remove the USB microphone from that machine, I won't have any microphone input to use. Instead I tested it on two laptops using their built-in microphones:

Framework Laptop 16 (Fedora Linux 40): Firefox 126 repros inconsistently. Chrome 125 repros more consistently but occasionally works.

Surface Pro 4 (Windows 10): Firefox 126 repros inconsistently. Edge reproed once on the very first try but never reproed again.

According to the spec the inputs array for a source can be empty if the source node is not "actively processing". Perhaps there is, on some OS/browser combinations, a moment after initialization where the microphone stream node is not actively processing.

msqr1 commented 5 months ago

@tdcook Can you recheck (latest commit on main)?

tdcook commented 5 months ago

Looks good, thanks!