weakaudio.py 文件源码

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

项目:weakmon 作者: rtmrtmrtmrtm 项目源码 文件源码
def pya_callback(self, in_data, frame_count, time_info, status):
        import pyaudio

        if status != 0:
            self.junklog("pya_callback status %d\n" % (status))

        pcm = numpy.fromstring(in_data, dtype=numpy.int16)
        if self.chan == 1:
            pcm = pcm[self.chan::2]

        assert frame_count == len(pcm)

        # time of first sample in pcm[], in seconds since start.
        adc_time = time_info['input_buffer_adc_time']
        # time of last sample
        adc_end = adc_time + (len(pcm) / float(self.cardrate))

        if self.last_adc_end != None:
            expected = (adc_end - self.last_adc_end) * float(self.cardrate)
            expected = int(round(expected))
            shortfall = expected - len(pcm)
            if abs(shortfall) > 20:
                self.junklog("pya expected %d got %d" % (expected, len(pcm)))
                #if shortfall > 100:
                #    pcm = numpy.append(numpy.zeros(shortfall, dtype=pcm.dtype), pcm)

        self.last_adc_end = adc_end

        # translate time of last sample to UNIX time
        ut = time.time()
        st = self.pya_strm.get_time()
        unix_end = (adc_end - st) + ut

        self.cardlock.acquire()
        self.cardbufs.append([ pcm, unix_end ])
        self.cardlock.release()

        return ( None, pyaudio.paContinue )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号