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")
8 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")
8 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…

3 Likes

@Jonathan.Olesen , thank you for this! Can you help me get this to work in Dynamo 2.13 using CPython3?
I’m getting an error stating: FileNotFoundException : Unable to find assembly ‘System.Speech’. at Python.Runtime.CLRModule.AddReference*String name)[’ File “< string >”, line 13, in < module >\n’]

Here is my current code:

Blockquote # Enable Python support and load DesignScript library
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

Blockquote# The inputs to this node will be stored as a list in the IN variables.
speachstring = IN[0]

Blockquote# Place your code below this line
import clr
from System.Threading import Thread
Thread.Sleep(2000)
clr.AddReference(‘System.Speech’)
from System.Speech.Synthesis import SpeechSynthesizer
speechSynthesizer = SpeechSynthesizer()
speechSynthesizer.SpeakAsync(speachstring)

Blockquote# Assign your output to the OUT variable.
OUT = 0

2 posts were split to a new topic: System.Speech in CPython3