In this tutorial, we will introduce you how to convert a flac audio to wav in python. We will use python soundfile to implement it.
Convert Audio flac to wav
It is easy to convert, here is an example:
import soundfile import numpy wav_file = r'drama-02-005.flac' audio, sr = soundfile.read(wav_file) soundfile.write('drama-02-005.wav', audio, sr, 'PCM_16')
Then, we can convert drama-02-005.flac to drama-02-005.wav.
However, we can find an interesting thing.
Read flac and wav audio using soundfile
We can read flac and wav audio data and compare them.
Read flac
wav_file = r'drama-02-005.flac' audio, sr = soundfile.read(wav_file) print(audio[200:220]) print(audio.shape) print(sr)
Run this code, we will get:
[ 0.01165771 0.00906372 0.01480103 0.02606201 0.03927612 0.03259277 0.01361084 0.00549316 0.01748657 0.02841187 0.03866577 0.04016113 0.02236938 0.00088501 0.00335693 0.01687622 0.00473022 -0.01751709 -0.02236938 -0.01037598] (21177,)
Read wav file
wav_file = r'drama-02-005.wav' audio, sr = soundfile.read(wav_file) print(audio[200:220]) print(audio.shape) print(sr)
We also will get:
[ 0.01165771 0.00906372 0.01480103 0.02606201 0.03927612 0.03259277 0.01361084 0.00549316 0.01748657 0.02841187 0.03866577 0.04016113 0.02236938 0.00088501 0.00335693 0.01687622 0.00473022 -0.01751709 -0.02236938 -0.01037598] (21177,) 16000
We can find: audo data from flac and wav are the same.