本文整理汇总了Python中audioop.ulaw2lin方法的典型用法代码示例。如果您正苦于以下问题:Python audioop.ulaw2lin方法的具体用法?Python audioop.ulaw2lin怎么用?Python audioop.ulaw2lin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类audioop
的用法示例。
在下文中一共展示了audioop.ulaw2lin方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ulaw2lin
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import ulaw2lin [as 别名]
def test_ulaw2lin(self):
encoded = b'\x00\x0e\x28\x3f\x57\x6a\x76\x7c\x7e\x7f'\
b'\x80\x8e\xa8\xbf\xd7\xea\xf6\xfc\xfe\xff'
src = [-8031, -4447, -1471, -495, -163, -53, -18, -6, -2, 0,
8031, 4447, 1471, 495, 163, 53, 18, 6, 2, 0]
for w in 1, 2, 3, 4:
decoded = packs[w](*(x << (w * 8) >> 14 for x in src))
self.assertEqual(audioop.ulaw2lin(encoded, w), decoded)
self.assertEqual(audioop.ulaw2lin(bytearray(encoded), w), decoded)
self.assertEqual(audioop.ulaw2lin(memoryview(encoded), w), decoded)
# Current u-law implementation has two codes fo 0: 0x7f and 0xff.
encoded = bytes(range(127)) + bytes(range(128, 256))
for w in 2, 3, 4:
decoded = audioop.ulaw2lin(encoded, w)
self.assertEqual(audioop.lin2ulaw(decoded, w), encoded)
示例2: test_play_sound_file
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import ulaw2lin [as 别名]
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()
示例3: readframes
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import ulaw2lin [as 别名]
def readframes(self, nframes):
if self._encoding in _simple_encodings:
if nframes == AUDIO_UNKNOWN_SIZE:
data = self._file.read()
else:
data = self._file.read(nframes * self._framesize * self._nchannels)
if self._encoding == AUDIO_FILE_ENCODING_MULAW_8:
import audioop
data = audioop.ulaw2lin(data, self._sampwidth)
return data
return None # XXX--not implemented yet
示例4: setsampwidth
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import ulaw2lin [as 别名]
def setsampwidth(self, width):
for (raw, cooked) in self.sampwidthlist:
if width == raw:
self.config.setwidth(cooked)
self.inited_width = 1
break
else:
if width == 0:
import AL
self.inited_width = 0
self.config.setwidth(AL.SAMPLE_16)
self.converter = self.ulaw2lin
else:
raise error, 'bad sample width'
示例5: ulaw2lin
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import ulaw2lin [as 别名]
def ulaw2lin(self, data):
import audioop
return audioop.ulaw2lin(data, 2)
示例6: _ulaw2lin
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import ulaw2lin [as 别名]
def _ulaw2lin(self, data):
import audioop
return audioop.ulaw2lin(data, 2)
示例7: readframes
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import ulaw2lin [as 别名]
def readframes(self, nframes):
if self._encoding in _simple_encodings:
if nframes == AUDIO_UNKNOWN_SIZE:
data = self._file.read()
else:
data = self._file.read(nframes * self._framesize)
self._soundpos += len(data) // self._framesize
if self._encoding == AUDIO_FILE_ENCODING_MULAW_8:
import audioop
data = audioop.ulaw2lin(data, self._sampwidth)
return data
return None # XXX--not implemented yet
示例8: read_sound_file
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import ulaw2lin [as 别名]
def read_sound_file(path):
with open(path, 'rb') as fp:
au = sunau.open(fp)
rate = au.getframerate()
nchannels = au.getnchannels()
encoding = au._encoding
fp.seek(0)
data = fp.read()
if encoding != sunau.AUDIO_FILE_ENCODING_MULAW_8:
raise RuntimeError("Expect .au file with 8-bit mu-law samples")
# Convert the data to 16-bit signed.
data = audioop.ulaw2lin(data, 2)
return (data, rate, 16, nchannels)
示例9: test_ulaw2lin
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import ulaw2lin [as 别名]
def test_ulaw2lin(self):
encoded = b'\x00\x0e\x28\x3f\x57\x6a\x76\x7c\x7e\x7f'\
b'\x80\x8e\xa8\xbf\xd7\xea\xf6\xfc\xfe\xff'
src = [-8031, -4447, -1471, -495, -163, -53, -18, -6, -2, 0,
8031, 4447, 1471, 495, 163, 53, 18, 6, 2, 0]
for w in 1, 2, 4:
self.assertEqual(audioop.ulaw2lin(encoded, w),
packs[w](*(x << (w * 8) >> 14 for x in src)))
# Current u-law implementation has two codes fo 0: 0x7f and 0xff.
encoded = ''.join(chr(x) for x in range(127) + range(128, 256))
for w in 2, 4:
decoded = audioop.ulaw2lin(encoded, w)
self.assertEqual(audioop.lin2ulaw(decoded, w), encoded)
示例10: test_wrongsize
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import ulaw2lin [as 别名]
def test_wrongsize(self):
data = b'abcdefgh'
state = None
for size in (-1, 0, 3, 5, 1024):
self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)