_recorder.py 文件源码

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

项目:aiyprojects-raspbian 作者: google 项目源码 文件源码
def run(self):
        """Reads data from arecord and passes to processors."""

        self._arecord = subprocess.Popen(self._cmd, stdout=subprocess.PIPE)
        logger.info("started recording")

        # Check for race-condition when __exit__ is called at the same time as
        # the process is started by the background thread
        if self._closed:
            self._arecord.kill()
            return

        this_chunk = b''

        while True:
            input_data = self._arecord.stdout.read(self._chunk_bytes)
            if not input_data:
                break

            this_chunk += input_data
            if len(this_chunk) >= self._chunk_bytes:
                self._handle_chunk(this_chunk[:self._chunk_bytes])
                this_chunk = this_chunk[self._chunk_bytes:]

        if not self._closed:
            logger.error('Microphone recorder died unexpectedly, aborting...')
            # sys.exit doesn't work from background threads, so use os._exit as
            # an emergency measure.
            logging.shutdown()
            os._exit(1)  # pylint: disable=protected-access
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号