Songs "fade" effect in a playList / Song duration

Hi! When you make an audio playList with aud module, you may want to use fade functions from Blender API:

fadein function is easy to use because we know that we want to apply a fade effect at the beginning of the song. So the start time of fadein is 0.

But when you want to apply a fade effect to the end of the song, you have to tell the fadeout function the moment the fade effect must begin. So you have to know the song duration. As far I know, it’s impossible with aud module. But I found a nice library in one .py file (so you can easily pack it into your .blend): tinytag

With this module, you can easily find the duration of a song:

from tinytag import TinyTag

song = TinyTag.get(songPath)
songDuration = song.duration 

So now, you can use fadeout function:

import aud

device = aud.device()

fac = aud.Factory(songPath)

fac = fac.fadein(0, 5) # Fade effect at the beginning of the song, 5 seconds length
fac = fac.fadeout(songDuration-5, 5) # Fade effect at the end of the song, 5 seconds length # play the song!

(In my example, 2/3 songs are already “faded out” :o, but it’s just for example)

Maybe someone knows an easier way to do that, but I share the tip nevertheless…

its perfect thanks youle

ah one thing. when all the songs are played, it doesnt continue playing again. What should we do so that it will be never end?


myFactoryObject = myFactoryObject.loop(-1) #loop(count)--negative value = infinite (aud API)

thanks youle

youle, if i use ogg typed- audio files. The sound can be stretched off or shrinked together ( faster or slower than usual) How can i fix it?