How can I programmatically determine the sampling rate and bitrate of a WAV file?

320 Views Asked by At

There is a program written in python which recognizes text with the vosk library used. To recognize text you need to pass the sampling rate and the language model with this line : KaldiRecognizer(model, 96000), where 96000 is the frequency itself. to define the sampling rate of the file I use the following code

with wave.open(r'a.wav', 'rb') as wave_file:
    frame_rate = wave_file.getframerate()
    print(frame_rate)

BUT! Virtually all of the files it determines the frequency: 48000, for some audio files, it is somehow not suitable and is displayed some nonsense and not the text (just a set of words), that is, vosk does not properly determine the text in audio, this problem is solved by replacing the frequency manual to the right, always need to select it. what could be the problem? before that, converted an audio file in online conversion. I would like to automate the process.

I tried converting an audio file with a pre-recorded sampling rate:

audio_file = 'a.wav'
y, sr = librosa.load(audio_file, sr=48000)
0

There are 0 best solutions below