--- a/snd.py +++ b/snd.py @@ -10,12 +10,14 @@ from array import array from struct import unpack, pack import threading +from pydispatch import dispatcher CHANNELS = 1 THRESHOLD = 500 CHUNK_SIZE = 1024 FORMAT = pyaudio.paInt16 RATE = 44100 +MAX_SILENT = 30 def is_silent(L): "Returns `True` if below the 'silent' threshold" @@ -97,9 +99,10 @@ num_silent += 1 print num_silent elif not silent and not snd_started: + dispatcher.send( signal='SND_STARTED') snd_started = True print snd_started - if snd_started and num_silent > 30: + if snd_started and num_silent > MAX_SILENT: break sample_width = p.get_sample_size(FORMAT)