I've trying to change the format of all my pack samples, from .WAV to FLAC. I made a script that checks all the subdirectories and finds file paths (WAV files specifically), and after find, it uses Pydub to convert the files. The problem is that the FLAC output bit rate is too smaller than the WAV file. My code below:
import os
import tnt # My library to get subdirectories
from pydub import AudioSegment
__all__ = ['convert', 'convert_all']
def convert(file_path, remove=False):
file = AudioSegment.from_wav(file_path)
# Parameters should be passed here, but I really don't know how to keep
# the highest bit rate possible according with the input file bit depth.
# By Default the output bit rate is about 300 kb/s.
file.export(file_path.replace('.wav', '.flac'), format='flac')
if remove:
os.remove(file_path)
def convert_all(root_path, remove=False):
file_names = tnt.DirWalker(root_path).get_file_names()
for f in file_names:
if f.endswith('.wav'):
convert(f, remove)
Please, a command to put on os.system('ffmpeg -i "input.wav" "output.flac"')
to get highest bit rate possible according with the original file bit depth would be nice too.