I have mp3 files that I'm trying to convert to 8, 24 or 32 bits, I was trying to do it using AudioSegment module using the following:
audio = AudioSegment.from_mp3('audio.mp3')
audio.resample(sample_width=1)
which returns an error: AttributeError: 'AudioSegment' object has no attribute 'resample'
(I found resample(sample_rate_Hz=None, sample_width=None, channels=None, console_output=False)
in AudioSegment documentation.)
I tried to convert mp3 files to wav and then change sample width using the following function:
def quantify(audio,k):
#audio: wave object \ k : new sample width
sw = audio.getsampwidth()
typ = {1:np.int8, 2:np.int16, 4:np.int32}
data = get_data(audio) #returns numpy array
newdata = data.astype(typ.get(k))
#I can then write this new data to a new wav file
return newdata
But using this way I think it's added work to convert from mp3 to wav to mp3 again, also using this method I can't convert to 24 bits since Numpy has no data type for that from what I've read (I don't know if it's possible with AudioSegment either). Any Suggestions?