5
$\begingroup$

I was looking into a really necessary function for me when using Blender. I need Blender to play a short mp3 sound when it finishes rendering. I found this on the API:

bpy.app.handlers.render_complete

Callback list - on completion of render job

And this script .py (addon) sends email notification, but I was really looking for .mp3 playback of a sound. Say for example if you are away from the computer, then you´ll hear the render fininsh. https://archive.blender.org/wiki/index.php/Extensions:2.6/Py/Scripts/Render/Notify_after_render/

But I don´t have a way to put this all together. Could someone point me with another script?

$\endgroup$
2

1 Answer 1

6
$\begingroup$

The aud module

For a standard the ubiquitous wave module to play ".wav" files would be a failsafe way to go.

However, Blender comes with the aud module which plays any format of sound that can be used in blender. My build supports:

>>> bpy.path.extensions_audio
frozenset({'.aac', '.oga', '.mka', '.eac3', '.aiff', '.aif', '.wav', '.mp2', '.ogg', '.flac', '.ac3', '.mp3', '.m4a', '.wma'})

Test script, edit the path to match path to audio file.

import bpy
import aud

path = "/home/batfinger/Music/CCR Chronicle, Vol. 1 - The 20 Greatest Hits/DISC/Creedence Clearwater Revival - Suzy Q. (Part 1) - 13.mp3"
# load the sound
snd = aud.Sound(path)
dev = aud.Device()

def finish_render(scene):
    dev.play(snd)
    return None

# clear others, assuming this is only one.    
bpy.app.handlers.render_complete.clear()
# assign handler.  
bpy.app.handlers.render_complete.append(finish_render)

Here is the way to stop the playback.

>>> import aud
>>> dev = aud.Device()
>>> dev.stopAll()
$\endgroup$
4
  • $\begingroup$ when you mention "here's a way to stop the playback": do you mean the sound keeps on playing with this script? I just want a short "blink.mp3" to play so I know afar that the render ended. Thanks. Great script. $\endgroup$ Feb 16, 2019 at 7:06
  • $\begingroup$ Plays it once. I tested with a 10min song, so I thought I'd add how to stop sound. $\endgroup$
    – batFINGER
    Feb 16, 2019 at 7:08
  • $\begingroup$ yeah. I definetly test it with a quick .mp3. But this is good to know (how to stop it as well). Amazing. Thanks.! $\endgroup$ Feb 16, 2019 at 7:55
  • 7
    $\begingroup$ This should really be an official plugin for Blender... $\endgroup$ Feb 16, 2019 at 12:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .