When we are building voice recognition model, we should convert alaw format audio file to pcm format. In this tutorial, we will introduce you how to convert.
View audio data format
In order to check what is the data format of your audio file, you can use ffprobe application. Here is a tutorial:
View Audio Sample Rate, Data Format PCM or ALAW Using ffprobe – Python Tutorial
How to convert audio alaw to pcm?
We can use python soundfile library.
There are some steps to convert.
Step 1: read audio data
We can use librosa to read. Here is an example:
import librosa import soundfile as sf v3 = r'F:\2351349.V3' audio, sr = librosa.load(v3, sr= c.SAMPLE_RATE, mono=True)
Step 2: save audio data to pcm
Here are PCM_16, PCM_32, you can select one to save.
sf.write('stereo_file.wav', audio, sr, 'PCM_16')
Then we will convert alaw 2351349.V3 to pcm 16 stereo_file.wav
Step 3: you use code below to check what formats supported by soundfile
print(sf.available_subtypes('WAV'))
Run this code, you will see:
{'PCM_16': 'Signed 16 bit PCM', 'PCM_24': 'Signed 24 bit PCM', 'PCM_32': 'Signed 32 bit PCM', 'PCM_U8': 'Unsigned 8 bit PCM', 'FLOAT': '32 bit float', 'DOUBLE': '64 bit float', 'ULAW': 'U-Law', 'ALAW': 'A-Law', 'IMA_ADPCM': 'IMA ADPCM', 'MS_ADPCM': 'Microsoft ADPCM', 'GSM610': 'GSM 6.10', 'G721_32': '32kbs G721 ADPCM'}