def sound(x,fs):
""" Plays a wave file using the pyglet library. But first, it has to be written.
Termination of the playback is being performed by any keyboard input and Enter.
Args:
x: (array) Floating point samples
fs: (int) The sampling rate
"""
import pyglet as pg
global player
# Call the writing function
AudioIO.wavWrite(x, fs, 16, 'testPlayback.wav')
# Initialize playback engine
player = pg.media.Player()
# Initialize the object with the audio file
playback = pg.media.load('testPlayback.wav')
# Set it to player
player.queue(playback)
# Sound call
player.play()
# Killed by "keyboard"
kill = raw_input()
if kill or kill == '':
AudioIO.stop()
# Remove the dummy wave write
os.remove('testPlayback.wav')
评论列表
文章目录