Is there a way to play a sound after a script finishes ? For scripts taking between 30min and many hours (like the delaunay triangulation one from doomlysz), it's good to not have to check every 10 min if the job is done or not.
2 Answers
You could play a MP3 file using the aud module
import aud
import time
sound = aud.Factory.file(pathToMP3 )
device = aud.device()
handle = device.play(sound)
# omit this to play full sound file
time.sleep(5)
handle.stop()
Alternatively you could launch any external application as described here: Run an external application with the bge
-
1$\begingroup$ It gives me this error today: AttributeError: module 'aud' has no attribute 'Factory' $\endgroup$ Commented Jan 30, 2020 at 11:08
-
$\begingroup$ Hm, the current version should stil support this docs.blender.org/api/current/aud.html you could post a new question for your 2.8? Version $\endgroup$– stackerCommented Jan 30, 2020 at 12:05
-
$\begingroup$ Yes, I know. Strange. Maybe my installation is broken somehow. $\endgroup$ Commented Jan 30, 2020 at 12:41
I solved this by using winsound. As it is for windows, it is not available to all blender user.
https://docs.python.org/2/library/winsound.html#module-winsound
I do a distinctive beep like this. I don't have to search for an suitable mp3.
import winsound
frequency = 2500 # Set Frequency To 2500 Hertz
duration = 1000 # Set Duration To 1000 ms == 1 second
winsound.Beep(frequency, duration)
I got it from this answer here:
https://stackoverflow.com/questions/6537481/python-making-a-beep-noise/45079462