-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsound.py
More file actions
34 lines (26 loc) · 913 Bytes
/
sound.py
File metadata and controls
34 lines (26 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /bin/env python
#Source: http://pymedia.org/
import threading
def playWAV( fname ):
import pymedia.audio.sound as sound
import time, wave
f= wave.open( fname, 'rb' )
sampleRate= f.getframerate()
channels= f.getnchannels()
format= sound.AFMT_S16_LE
snd1= sound.Output( sampleRate, channels, format )
s= ' '
while len( s ):
s= f.readframes( 1000 )
snd1.play( s )
#Since sound module is not synchronous we want everything to be played before we exit
while snd1.isPlaying():
time.sleep( 0.05 )
def playWAV_threaded(fname): #This should always be used instead of playWAV, because sleep() will halt the program otherwise.
t = threading.Thread(target=playWAV,args=[fname])
t.start()
# ----------------------------------------------------------------------------------
# Play a wav file through the sound object
# http://pymedia.org/
if __name__== '__main__':
playWAV('friend_log_in.wav')