I've made this class:
class AudioSegmentCustom(AudioSegment):
def fade_override(self, seg, fade_len=100):
seg1, seg2 = AudioSegment._sync(self, seg)
final = seg1[:-fade_len]
a_fin = seg1[-fade_len:].fade(to_gain=-120, start=0, end=float('inf'))
a_fin *= seg2[:fade_len]
return (final + a_fin) + seg2[fade_len:]
The problem I'm facing is when I create some AudioSegmentCustom
variables, if I "add" them, the add
operation returns its original parent type = AudioSegment
Thus the following code doesn't work:
final = AudioSegmentCustom.from_mp3(mp3_src) + AudioSegment.from_mp3(mp3_other)
final = final.fade_override(...blabla...)
because I get:
'AudioSegment' object has no attribute 'fade_override'
...even though I've started with a AudioSegmentCustom
object, I end with AudioSegment
"only" object.
What is the way to "force" the type of a newly created object?
Just in case you need it:
class AudioSegment(object):
def __add__(self, arg):
if isinstance(arg, AudioSegment):
return self.append(arg, crossfade=0)
else:
return self.apply_gain(arg)