def read_chunks(self, size):
device_index = None
# for i in range(self.pyaudio_instance.get_device_count()):
# dev = self.pyaudio_instance.get_device_info_by_index(i)
# name = dev['name'].encode('utf-8')
# print(i, name, dev['maxInputChannels'], dev['maxOutputChannels'])
# if dev['maxInputChannels'] >= self.channels:
# print('Use {}'.format(name))
# device_index = i
# break
# if not device_index:
# print('can not find input device with {} channel(s)'.format(self.channels))
# return
stream = self.pyaudio_instance.open(
input=True,
format=pyaudio.paInt16,
channels=self.channels,
rate=self.sample_rate,
frames_per_buffer=size,
stream_callback=self._callback,
input_device_index = device_index,
)
while not self.quit_event.is_set():
frames = self.queue.get()
if not frames:
break
yield frames
stream.close()
评论列表
文章目录