def normalize(self):
"""
Normalize the sample, meaning: convert it to the default samplerate, sample width and number of channels.
When mixing samples, they should all have the same properties, and this method is ideal to make sure of that.
"""
assert not self.__locked
self.resample(self.norm_samplerate)
if self.samplewidth != self.norm_samplewidth:
# Convert to 16 bit sample size.
self.__frames = audioop.lin2lin(self.__frames, self.samplewidth, self.norm_samplewidth)
self.__samplewidth = self.norm_samplewidth
if self.nchannels == 1:
# convert to stereo
self.__frames = audioop.tostereo(self.__frames, self.samplewidth, 1, 1)
self.__nchannels = 2
return self
评论列表
文章目录