Division by NoneType in TimeStretch
slychief opened this issue · 1 comments
slychief commented
The attempt to produce a time stretch transformation to an audio file raises a type error exception due to a division by a None type.
import jams
import muda
audiofile = "D:/temp/test.mp3"
jam = jams.JAMS()
jam = muda.jam_pack(jam)
jam = muda.core.load_jam_audio(jam, audiofile)
# this works
P = muda.deformers.PitchShift(n_semitones=5)
out_jams = list(P.transform(jam))
# this not
T = muda.deformers.TimeStretch(rate=2.0)
out_jams = list(T.transform(jam))
produces the following error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-30-603bfe0e77bc> in <module>()
13
14 T = muda.deformers.TimeStretch(rate=2.0)
---> 15 out_jams = list(T.transform(jam))
C:\Anaconda\lib\site-packages\muda-0.1.1-py2.7.egg\muda\base.pyc in transform(self, jam)
141
142 for state in self.states(jam):
--> 143 yield self._transform(jam, state)
144
145 @property
C:\Anaconda\lib\site-packages\muda-0.1.1-py2.7.egg\muda\base.pyc in _transform(self, jam, state)
112
113 if hasattr(self, 'metadata'):
--> 114 self.metadata(jam_w.file_metadata, state)
115
116 # Walk over the list of deformers
C:\Anaconda\lib\site-packages\muda-0.1.1-py2.7.egg\muda\deformers\time.pyc in metadata(metadata, state)
40 def metadata(metadata, state):
41 # Deform the metadata
---> 42 metadata.duration /= state['rate']
43
44 @staticmethod
TypeError: unsupported operand type(s) for /=: 'NoneType' and 'float'
bmcfee commented
Aha, good catch.
It looks like the file_metadata.duration
field is not getting initialized in load_jam_audio
. This is an easy fix.
In the meantime, you can patch around this by setting the duration field manually after loading:
jam = muda.jam_pack(jam)
jam = muda.core.load_jam_audio(jam, audiofile)
jam.file_metadata.duration = librosa.get_duration(filename=audiofile)
# proceed as before