Want to play a sound when script is done

How can i play a sound at the end of my script…

2 Likes

Personally I use the following python snip:

import clr
import winsound
duration = 2500  # millisecond
freq = 440  # Hz
winsound.Beep(freq, duration)

#Assign your output to the OUT variable.
OUT = "Success"

Setting a simple “dummy”-input from the end of your graph will delay the sound till that portion of the graph have run.

and if i want to run an mp3…

Apart from writing a C# script with the song I do not believe that is possible using the IronPython shell.

May I ask why you require the ability to play a mp3 on completion?

My best guess … he’s proud of his script :muscle:

1 Like

we have very complex drawings, printing drawings can take up to 40min to complete…i made a script that handles the printing, but i wan’t an audio file to make notice that the printing is done.

and running an mp3 is then just fun…

but i must be possible to just run a file…

You can make your computer talk giving the user a talking heads-up :slight_smile:

import clr
clr.AddReference('System.Speech')
from System.Speech.Synthesis import SpeechSynthesizer
speechSynthesizer = SpeechSynthesizer()
speechSynthesizer.SpeakAsync("Your graph have now finished making awesome drawings")
5 Likes

Hi Arno,

This ought to open any file with the default application:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import System

import os
#Assign your output to the OUT variable.
OUT = os.startfile(r"C:\Taco\music\De Kift - Bal\01 Bal.mp3")
7 Likes

You can use SoundPlayer to play .wav files.

import clr
from System.Media import SoundPlayer
sp = SoundPlayer()
sp.SoundLocation = “C:\my.wav”
sp.Play()

1 Like

And here is something to play if the Dynamo graph needs help :slight_smile:

import winsound
import time

f1 = 800
f2 = 800
d1 = 110
d2 = 210
s1 = 0.3
s2 = 1.2
for i in range(0,4):
	winsound.Beep(f1, d1)
	winsound.Beep(f1, d1)
	winsound.Beep(f1, d1)
	time.sleep(s1)
	winsound.Beep(f2, d2)
	winsound.Beep(f2, d2)
	winsound.Beep(f2, d2)
	time.sleep(s1)
	winsound.Beep(f1, d1)
	winsound.Beep(f1, d1)
	winsound.Beep(f1, d1)
	time.sleep(s2)



#Assign your output to the OUT variable.
OUT = "Success"
2 Likes

Ah, good old winsound… My favourite…

2 Likes