本文整理汇总了Python中audioop.avg方法的典型用法代码示例。如果您正苦于以下问题:Python audioop.avg方法的具体用法?Python audioop.avg怎么用?Python audioop.avg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类audioop
的用法示例。
在下文中一共展示了audioop.avg方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_issue7673
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import avg [as 别名]
def test_issue7673(self):
state = None
for data, size in INVALID_DATA:
size2 = size
self.assertRaises(audioop.error, audioop.getsample, data, size, 0)
self.assertRaises(audioop.error, audioop.max, data, size)
self.assertRaises(audioop.error, audioop.minmax, data, size)
self.assertRaises(audioop.error, audioop.avg, data, size)
self.assertRaises(audioop.error, audioop.rms, data, size)
self.assertRaises(audioop.error, audioop.avgpp, data, size)
self.assertRaises(audioop.error, audioop.maxpp, data, size)
self.assertRaises(audioop.error, audioop.cross, data, size)
self.assertRaises(audioop.error, audioop.mul, data, size, 1.0)
self.assertRaises(audioop.error, audioop.tomono, data, size, 0.5, 0.5)
self.assertRaises(audioop.error, audioop.tostereo, data, size, 0.5, 0.5)
self.assertRaises(audioop.error, audioop.add, data, data, size)
self.assertRaises(audioop.error, audioop.bias, data, size, 0)
self.assertRaises(audioop.error, audioop.reverse, data, size)
self.assertRaises(audioop.error, audioop.lin2lin, data, size, size2)
self.assertRaises(audioop.error, audioop.ratecv, data, size, 1, 1, 1, state)
self.assertRaises(audioop.error, audioop.lin2ulaw, data, size)
self.assertRaises(audioop.error, audioop.lin2alaw, data, size)
self.assertRaises(audioop.error, audioop.lin2adpcm, data, size, state)
示例2: test_avg
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import avg [as 别名]
def test_avg(self):
for w in 1, 2, 3, 4:
self.assertEqual(audioop.avg(b'', w), 0)
self.assertEqual(audioop.avg(bytearray(), w), 0)
self.assertEqual(audioop.avg(memoryview(b''), w), 0)
p = packs[w]
self.assertEqual(audioop.avg(p(5), w), 5)
self .assertEqual(audioop.avg(p(5, 8), w), 6)
self.assertEqual(audioop.avg(p(5, -8), w), -2)
self.assertEqual(audioop.avg(p(maxvalues[w], maxvalues[w]), w),
maxvalues[w])
self.assertEqual(audioop.avg(p(minvalues[w], minvalues[w]), w),
minvalues[w])
self.assertEqual(audioop.avg(packs[4](0x50000000, 0x70000000), 4),
0x60000000)
self.assertEqual(audioop.avg(packs[4](-0x50000000, -0x70000000), 4),
-0x60000000)
示例3: test_string
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import avg [as 别名]
def test_string(self):
data = 'abcd'
size = 2
self.assertRaises(TypeError, audioop.getsample, data, size, 0)
self.assertRaises(TypeError, audioop.max, data, size)
self.assertRaises(TypeError, audioop.minmax, data, size)
self.assertRaises(TypeError, audioop.avg, data, size)
self.assertRaises(TypeError, audioop.rms, data, size)
self.assertRaises(TypeError, audioop.avgpp, data, size)
self.assertRaises(TypeError, audioop.maxpp, data, size)
self.assertRaises(TypeError, audioop.cross, data, size)
self.assertRaises(TypeError, audioop.mul, data, size, 1.0)
self.assertRaises(TypeError, audioop.tomono, data, size, 0.5, 0.5)
self.assertRaises(TypeError, audioop.tostereo, data, size, 0.5, 0.5)
self.assertRaises(TypeError, audioop.add, data, data, size)
self.assertRaises(TypeError, audioop.bias, data, size, 0)
self.assertRaises(TypeError, audioop.reverse, data, size)
self.assertRaises(TypeError, audioop.lin2lin, data, size, size)
self.assertRaises(TypeError, audioop.ratecv, data, size, 1, 1, 1, None)
self.assertRaises(TypeError, audioop.lin2ulaw, data, size)
self.assertRaises(TypeError, audioop.lin2alaw, data, size)
self.assertRaises(TypeError, audioop.lin2adpcm, data, size, None)
示例4: test_avg
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import avg [as 别名]
def test_avg(self):
for w in 1, 2, 4:
self.assertEqual(audioop.avg(b'', w), 0)
p = packs[w]
self.assertEqual(audioop.avg(p(5), w), 5)
self .assertEqual(audioop.avg(p(5, 8), w), 6)
self.assertEqual(audioop.avg(p(5, -8), w), -2)
self.assertEqual(audioop.avg(p(maxvalues[w], maxvalues[w]), w),
maxvalues[w])
self.assertEqual(audioop.avg(p(minvalues[w], minvalues[w]), w),
minvalues[w])
self.assertEqual(audioop.avg(packs[4](0x50000000, 0x70000000), 4),
0x60000000)
self.assertEqual(audioop.avg(packs[4](-0x50000000, -0x70000000), 4),
-0x60000000)
示例5: testavg
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import avg [as 别名]
def testavg(data):
if verbose:
print 'avg'
if audioop.avg(data[0], 1) != 1 or \
audioop.avg(data[1], 2) != 1 or \
audioop.avg(data[2], 4) != 1:
return 0
return 1
示例6: testbias
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import avg [as 别名]
def testbias(data):
if verbose:
print 'bias'
# Note: this test assumes that avg() works
d1 = audioop.bias(data[0], 1, 100)
d2 = audioop.bias(data[1], 2, 100)
d4 = audioop.bias(data[2], 4, 100)
if audioop.avg(d1, 1) != 101 or \
audioop.avg(d2, 2) != 101 or \
audioop.avg(d4, 4) != 101:
return 0
return 1
示例7: record
# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import avg [as 别名]
def record(threshold=THRESHOLD, silence=SILENCE_LIMIT):
"""
Listens to Microphone, records voice until phrase ends.
A "phrase" is sound surrounded by silence (according to threshold).
:param int threshold: Intensity value that defines silence.
lower than threshold is silence.
:param silence: Max ammount of seconds where only silence is
recorded. When this time passes the recording finishes.
"""
# Open stream
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print ("* Listening mic. ")
frames = []
cur_data = ''
rel = RATE/CHUNK
window = deque(maxlen=silence * rel)
prev_audio = deque(maxlen=PREV_AUDIO * rel)
start = False
exit_loop = 0
while (exit_loop != 1):
cur_data = stream.read(CHUNK)
window.append(math.sqrt(abs(audioop.avg(cur_data, 4))))
if(sum([x > THRESHOLD for x in window]) > 0):
if(not start):
print ("recording..")
start = True
frames.append(cur_data)
elif start is True:
print ("Finished")
save_audio(list(prev_audio) + frames, p)
start = False
window = deque(maxlen=silence * rel)
prev_audio = deque(maxlen=0.5 * rel)
frames = []
exit_loop = 1
else:
prev_audio.append(cur_data)
print ("Done recording")
stream.close()
p.terminate()