Fix for exception due to missing buzzer.wav

This commit is contained in:
daniel-123 2013-01-07 21:26:48 +01:00
parent cbdf10075e
commit 38669acc44
1 changed files with 19 additions and 16 deletions

View File

@ -15,21 +15,24 @@ def doBuzz():
winsound.PlaySound(buzzPath, winsound.SND_FILENAME|winsound.SND_ASYNC)
elif(alsaaudio):
buzzPath = utils.findWorkingDir() + "/resources/buzzer.wav"
buzz = wave.open(buzzPath, 'rb')
device = alsaaudio.PCM(0)
device.setchannels(buzz.getnchannels())
device.setrate(buzz.getframerate())
if buzz.getsampwidth() == 1:
device.setformat(alsaaudio.PCM_FORMAT_U8)
elif buzz.getsampwidth() == 2:
device.setformat(alsaaudio.PCM_FORMAT_S16_LE)
else:
raise ValueError('Unsupported buzzer format')
device.setperiodsize(640)
data = buzz.readframes(640)
while data:
device.write(data)
print buzzPath
try:
buzz = wave.open(buzzPath, 'rb')
device = alsaaudio.PCM(0)
device.setchannels(buzz.getnchannels())
device.setrate(buzz.getframerate())
if buzz.getsampwidth() == 1:
device.setformat(alsaaudio.PCM_FORMAT_U8)
elif buzz.getsampwidth() == 2:
device.setformat(alsaaudio.PCM_FORMAT_S16_LE)
else:
raise ValueError('Unsupported buzzer format')
device.setperiodsize(640)
data = buzz.readframes(640)
buzz.close()
while data:
device.write(data)
data = buzz.readframes(640)
buzz.close()
except IOError:
pass