本文整理匯總了Python中aifc.open方法的典型用法代碼示例。如果您正苦於以下問題:Python aifc.open方法的具體用法?Python aifc.open怎麽用?Python aifc.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類aifc
的用法示例。
在下文中一共展示了aifc.open方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: writeframes
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def writeframes(self, data):
if not (self.inited_outrate and self.inited_width and self.inited_nchannels):
raise error, 'params not specified'
if not self.port:
import sunaudiodev, SUNAUDIODEV
self.port = sunaudiodev.open('w')
info = self.port.getinfo()
info.o_sample_rate = self.outrate
info.o_channels = self.nchannels
if self.sampwidth == 0:
info.o_precision = 8
self.o_encoding = SUNAUDIODEV.ENCODING_ULAW
# XXX Hack, hack -- leave defaults
else:
info.o_precision = 8 * self.sampwidth
info.o_encoding = SUNAUDIODEV.ENCODING_LINEAR
self.port.setinfo(info)
if self.converter:
data = self.converter(data)
self.port.write(data)
示例2: test
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test(fn = None):
import sys
if sys.argv[1:]:
fn = sys.argv[1]
else:
fn = 'f:just samples:just.aif'
import aifc
af = aifc.open(fn, 'r')
print fn, af.getparams()
p = AudioDev()
p.setoutrate(af.getframerate())
p.setsampwidth(af.getsampwidth())
p.setnchannels(af.getnchannels())
BUFSIZ = af.getframerate()/af.getsampwidth()/af.getnchannels()
while 1:
data = af.readframes(BUFSIZ)
if not data: break
print len(data)
p.writeframes(data)
p.wait()
示例3: test_write_params_singles
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test_write_params_singles(self):
fout = aifc.open(io.BytesIO(), 'wb')
fout.aifc()
fout.setnchannels(1)
fout.setsampwidth(2)
fout.setframerate(3)
fout.setnframes(4)
fout.setcomptype('NONE', 'name')
self.assertEqual(fout.getnchannels(), 1)
self.assertEqual(fout.getsampwidth(), 2)
self.assertEqual(fout.getframerate(), 3)
self.assertEqual(fout.getnframes(), 0)
self.assertEqual(fout.tell(), 0)
self.assertEqual(fout.getcomptype(), 'NONE')
self.assertEqual(fout.getcompname(), 'name')
fout.writeframes('\x00' * 4 * fout.getsampwidth() * fout.getnchannels())
self.assertEqual(fout.getnframes(), 4)
self.assertEqual(fout.tell(), 4)
示例4: test_compress
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test_compress(self):
f = self.f = aifc.open(self.sndfilepath)
fout = self.fout = aifc.open(TESTFN, 'wb')
fout.aifc()
fout.setnchannels(f.getnchannels())
fout.setsampwidth(f.getsampwidth())
fout.setframerate(f.getframerate())
fout.setcomptype('ULAW', 'foo')
for frame in range(f.getnframes()):
fout.writeframes(f.readframes(1))
fout.close()
self.assertLess(
os.stat(TESTFN).st_size,
os.stat(self.sndfilepath).st_size*0.75,
)
fout = self.fout = aifc.open(TESTFN, 'rb')
f.rewind()
self.assertEqual(f.getparams()[0:3], fout.getparams()[0:3])
self.assertEqual(fout.getcomptype(), 'ULAW')
self.assertEqual(fout.getcompname(), 'foo')
# XXX: this test fails, not sure if it should succeed or not
# self.assertEqual(f.readframes(5), fout.readframes(5))
示例5: test_close
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test_close(self):
class Wrapfile(object):
def __init__(self, file):
self.file = open(file, 'rb')
self.closed = False
def close(self):
self.file.close()
self.closed = True
def __getattr__(self, attr): return getattr(self.file, attr)
testfile = Wrapfile(self.sndfilepath)
f = self.f = aifc.open(testfile)
self.assertEqual(testfile.closed, False)
f.close()
self.assertEqual(testfile.closed, True)
testfile = open(TESTFN, 'wb')
fout = aifc.open(testfile, 'wb')
self.assertFalse(testfile.closed)
with self.assertRaises(aifc.Error):
fout.close()
self.assertTrue(testfile.closed)
fout.close() # do nothing
示例6: test
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test():
import aifc
import EasyDialogs
fn = EasyDialogs.AskFileForOpen(message="Select an AIFF soundfile", typeList=("AIFF",))
if not fn: return
af = aifc.open(fn, 'r')
print af.getparams()
p = Play_Audio_mac()
p.setoutrate(af.getframerate())
p.setsampwidth(af.getsampwidth())
p.setnchannels(af.getnchannels())
BUFSIZ = 10000
while 1:
data = af.readframes(BUFSIZ)
if not data: break
p.writeframes(data)
print 'wrote', len(data), 'space', p.getfillable()
p.wait()
示例7: test_aifc
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test_aifc(h, f):
import aifc
if not h.startswith(b'FORM'):
return None
if h[8:12] == b'AIFC':
fmt = 'aifc'
elif h[8:12] == b'AIFF':
fmt = 'aiff'
else:
return None
f.seek(0)
try:
a = aifc.open(f, 'r')
except (EOFError, aifc.Error):
return None
return (fmt, a.getframerate(), a.getnchannels(),
a.getnframes(), 8 * a.getsampwidth())
示例8: test_write_params_singles
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test_write_params_singles(self):
fout = aifc.open(io.BytesIO(), 'wb')
fout.aifc()
fout.setnchannels(1)
fout.setsampwidth(2)
fout.setframerate(3)
fout.setnframes(4)
fout.setcomptype(b'NONE', b'name')
self.assertEqual(fout.getnchannels(), 1)
self.assertEqual(fout.getsampwidth(), 2)
self.assertEqual(fout.getframerate(), 3)
self.assertEqual(fout.getnframes(), 0)
self.assertEqual(fout.tell(), 0)
self.assertEqual(fout.getcomptype(), b'NONE')
self.assertEqual(fout.getcompname(), b'name')
fout.writeframes(b'\x00' * 4 * fout.getsampwidth() * fout.getnchannels())
self.assertEqual(fout.getnframes(), 4)
self.assertEqual(fout.tell(), 4)
示例9: test_skipunknown
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test_skipunknown(self):
#Issue 2245
#This file contains chunk types aifc doesn't recognize.
self.f = aifc.open(findfile('Sine-1000Hz-300ms.aif'))
示例10: test_write_markers_values
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test_write_markers_values(self):
fout = aifc.open(io.BytesIO(), 'wb')
self.assertEqual(fout.getmarkers(), None)
fout.setmark(1, 0, 'foo1')
fout.setmark(1, 1, 'foo2')
self.assertEqual(fout.getmark(1), (1, 1, 'foo2'))
self.assertEqual(fout.getmarkers(), [(1, 1, 'foo2')])
fout.initfp(None)
示例11: test_read_markers
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test_read_markers(self):
fout = self.fout = aifc.open(TESTFN, 'wb')
fout.aiff()
fout.setparams((1, 1, 1, 1, 'NONE', ''))
fout.setmark(1, 0, 'odd')
fout.setmark(2, 0, 'even')
fout.writeframes('\x00')
fout.close()
f = self.f = aifc.open(TESTFN, 'rb')
self.assertEqual(f.getmarkers(), [(1, 0, 'odd'), (2, 0, 'even')])
self.assertEqual(f.getmark(1), (1, 0, 'odd'))
self.assertEqual(f.getmark(2), (2, 0, 'even'))
self.assertRaises(aifc.Error, f.getmark, 3)
示例12: test_read_wrong_form
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test_read_wrong_form(self):
b1 = io.BytesIO('WRNG' + struct.pack('>L', 0))
b2 = io.BytesIO('FORM' + struct.pack('>L', 4) + 'WRNG')
self.assertRaises(aifc.Error, aifc.open, b1)
self.assertRaises(aifc.Error, aifc.open, b2)
示例13: test_read_no_comm_chunk
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test_read_no_comm_chunk(self):
b = io.BytesIO('FORM' + struct.pack('>L', 4) + 'AIFF')
self.assertRaises(aifc.Error, aifc.open, b)
示例14: test_read_no_ssnd_chunk
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test_read_no_ssnd_chunk(self):
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
b += b'COMM' + struct.pack('>LhlhhLL', 38, 0, 0, 0, 0, 0, 0)
b += b'NONE' + struct.pack('B', 14) + b'not compressed' + b'\x00'
with self.assertRaisesRegexp(aifc.Error, 'COMM chunk and/or SSND chunk'
' missing'):
aifc.open(io.BytesIO(b))
示例15: test_read_wrong_compression_type
# 需要導入模塊: import aifc [as 別名]
# 或者: from aifc import open [as 別名]
def test_read_wrong_compression_type(self):
b = 'FORM' + struct.pack('>L', 4) + 'AIFC'
b += 'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0)
b += 'WRNG' + struct.pack('B', 0)
self.assertRaises(aifc.Error, aifc.open, io.BytesIO(b))