Reputation: 11
I'm working on converting audio obtained from phone calls to WAV files for playback. The audio has a sample rate of 8000 Hz and an AudioEncoding of LINEAR16. However, the resulting WAV file is very noisy and difficult to understand.
Here is the code I am using for the conversion:
import wave
import audioop
#audio_data is an example of how the audio comes
audio_data = (
b'@\x00X\x00p\x00h\x00X\x00H\x00@\x008\x00(\x00 \x00\x1f'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x18\x00\x08\x00\xf0\xff\xe8\xffx00H\x000\x00(\x00 \x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x0@\x00X\x00p\@\x00X'
)
#This part is optional and is to use decode G711u -- It works worse if I use it
audio_pcm = audioop.ulaw2lin(audio_data, 2)
with wave.open("output.wav", "wb") as wav_file:
# Configurar los parámetros del archivo WAV
wav_file.setnchannels(1) # Mono
wav_file.setsampwidth(2) # 16 bits por muestra
wav_file.setframerate(8000) # Frecuencia de muestreo
# Escribir los datos PCM al archivo
wav_file.writeframes(audio_pcm)
The output.wav file I get is very noisy and the words are almost inaudible. I have verified the following aspects:
• The sampling rate is correct (8000 Hz).
• The WAV file configuration appears correct.
• Another option I tried is to use decode G711u but it works worse.
Does anyone have any idea why the resulting audio is so noisy? Could there be a problem with the way the WAV file is being processed or configured?
Thanks for any help you can offer.
Upvotes: 0
Views: 46