alphacep / vosk-api

Offline speech recognition API for Android, iOS, Raspberry Pi and servers with Python, Java, C# and Node
Apache License 2.0
7.41k stars 1.04k forks source link

Feature addition: Save audio stream into .wav file (Python wrapper) #216

Open antondim opened 3 years ago

antondim commented 3 years ago

Hello,

would it be helpful to add my implementation of such a feature on "test_microphone.py" ?

This would enable someone (who's not very familiar with audio data manipulation) to listen to the (uncompressed and lossless) stream audio input which is parsed to the Recognizer for audio device debugging or w/e reasons.

aaronse commented 3 years ago

Was this done already? Sounds useful!

sskorol commented 3 years ago

It's quite easy to do in Python. Here's an example:

import wave

wav = wave.open(name, "wb")
wav.setparams((CHANNELS, 2, SAMPLE_RATE, 0, 'NONE', 'not compressed'))
wav.writeframes(audio_chunk)
wav.close()
antondim commented 3 years ago

Was this done already? Sounds useful!

I Added a simple version of test_microphone.py with wav saving option on a different branch of my forked version of vosk-api on my github.

Bear in mind that my initial version of "test_microphone.py" was of an older state of vosk-api. I did not check the updated versions, although I doubt that the logic would be any different. So you can somehow, incorporate the same logic on newer versions of "test_microphone.py" scripts.

GabiSchaffzin commented 11 months ago

I gave this a try and when I try to open the file in Media Player on Windows 11 and it won't open, showing the error:

We can't open [filename.wav]. This may be because the file type is unsupported, the file extension is incorrect or the file is corrupt. 0xC00D36C4

Any ideas on why that would be happening?