def read_sound_file(path): fp = open(path, 'rb') size, enc, rate, nchannels, extra = sunaudio.gethdr(fp) data = fp.read() fp.close() if enc != SND_FORMAT_MULAW_8: print "Expect .au file with 8-bit mu-law samples" return # Convert the data to 16-bit signed. data = audioop.ulaw2lin(data, 2) return (data, rate, 16, nchannels)
def play_sound_file(path): fp = open(path, 'r') size, enc, rate, nchannels, extra = sunaudio.gethdr(fp) data = fp.read() fp.close() if enc != SND_FORMAT_MULAW_8: print "Expect .au file with 8-bit mu-law samples" return try: a = linuxaudiodev.open('w') except linuxaudiodev.error, msg: if msg[0] in (errno.EACCES, errno.ENODEV): raise TestSkipped, msg raise TestFailed, msg
def play_sound_file(path): fp = open(path, 'r') size, enc, rate, nchannels, extra = sunaudio.gethdr(fp) data = fp.read() fp.close() if enc != SND_FORMAT_MULAW_8: print "Expect .au file with 8-bit mu-law samples" return try: a = linuxaudiodev.open('w') except linuxaudiodev.error, msg: if msg[0] in (errno.EACCES, errno.ENODEV, errno.EBUSY): raise TestSkipped, msg raise TestFailed, msg
def test_play_sound_file(self): path = findfile("audiotest.au") fp = open(path, 'r') size, enc, rate, nchannels, extra = sunaudio.gethdr(fp) data = fp.read() fp.close() if enc != SND_FORMAT_MULAW_8: self.fail("Expect .au file with 8-bit mu-law samples") # convert the data to 16-bit signed data = audioop.ulaw2lin(data, 2) # set the data format if sys.byteorder == 'little': fmt = linuxaudiodev.AFMT_S16_LE else: fmt = linuxaudiodev.AFMT_S16_BE # set parameters based on .au file headers self.dev.setparameters(rate, 16, nchannels, fmt) self.dev.write(data) self.dev.flush()
def playfile(name): if G.mode <> 'mac': tempname = name elif cache.has_key(name): tempname = cache[name] else: tempname = G.tempprefix + `rand.rand()` cmd = HOME_BIN_SGI + 'macsound2sgi' cmd = cmd + ' ' + commands.mkarg(name) cmd = cmd + ' >' + tempname if G.debug: print cmd sts = posix.system(cmd) if sts: print cmd print 'Exit status', sts stdwin.fleep() return cache[name] = tempname fp = open(tempname, 'r') try: hdr = sunaudio.gethdr(fp) except sunaudio.error, msg: hdr = ()
import sunaudio file = "samples/sample.au" print(sunaudio.gethdr(open(file, "rb"))) ## (6761, 1, 8012, 1, 'sample.au')
import sunaudio file = "samples/sample.au" print sunaudio.gethdr(open(file, "rb")) ## (6761, 1, 8012, 1, 'sample.au')
from test_support import verbose, findfile, TestFailed, TestSkipped