alphacep / vosk-server

WebSocket, gRPC and WebRTC speech recognition server based on Vosk and Kaldi libraries
Apache License 2.0
869 stars 241 forks source link

Javascript: Connecting AudioNodes from AudioContexts with different sample-rate is currently not supported. #214

Open leonardorame opened 1 year ago

leonardorame commented 1 year ago

Hi, in Firefox 102.0.1 (64-bit) I get this error in voice_client_with_audio_worklet.js line 72:

Uncaught (in promise) DOMException: AudioContext.createMediaStreamSource: Connecting AudioNodes from AudioContexts with different sample-rate is currently not supported.

Context:

My client is running on a different machine than the server. The server runs with a self signed certificate and wss instead of ws. Anyway, the websocket connection is established correctly, this issue raises when I try to open the microphone (line 72).

leonardorame commented 1 year ago

If I change the line 62 from this:

context = new AudioContext({sampleRate: sampleRate})

to this:

context = new AudioContext({)

The error dissapear, but the server (asr_server.py from vosk-server/websocket) can't process the audio, it receives the audio, but isn't able to process.

leonardorame commented 1 year ago

I found a way to process the audio:

  1. Change the line 62 to: context = new AudioContext({) and do a console.log(context)to see what is the browser's sampleRate.
  2. In line 99 of asr_server.py, change the VOSK_SAMPLE_RATE flag to match the browser's sampleRage, in my case 44100.

This way the recognition works, but it's not as accurate as when using the test_microphone.py example, which uses 8000 as sample rate.

nshmyrev commented 1 year ago

In general we recommend you to use webrtc server and webrtc client.

leonardorame commented 1 year ago

Thanks @nshmyrev, I'll try that.