player.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:respeaker_python_library 作者: respeaker 项目源码 文件源码
def _play(self, data, rate=16000, channels=1, width=2, spectrum=True):
        stream = self.pyaudio_instance.open(
            format=self.pyaudio_instance.get_format_from_width(width),
            channels=channels,
            rate=rate,
            output=True,
            # output_device_index=1,
            frames_per_buffer=CHUNK_SIZE,
        )

        if isinstance(data, types.GeneratorType):
            for d in data:
                if self.stop_event.is_set():
                    break

                stream.write(d)

                if spectrum:
                    if channels == 2:
                        d = audioop.tomono(d, 2, 0.5, 0.5)
                    self.queue.put(d)
        else:
            stream.write(data)

        stream.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号