__init__.py 文件源码

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

项目:pyrecord 作者: Aakashdeveloper 项目源码 文件源码
def __init__(self, device_index = None, sample_rate = None, chunk_size = None):
            assert device_index is None or isinstance(device_index, int), "Device index must be None or an integer"
            if device_index is not None: # ensure device index is in range
                audio = pyaudio.PyAudio(); count = audio.get_device_count(); audio.terminate() # obtain device count
                assert 0 <= device_index < count, "Device index out of range"
            assert sample_rate is None or isinstance(sample_rate, int) and sample_rate > 0, "Sample rate must be None or a positive integer"
            assert chunk_size is None or isinstance(chunk_size, int) and chunk_size > 0, "Chunk size must be None or a positive integer"
            if sample_rate is None: chunk_size = 16000
            if chunk_size is None: chunk_size = 1024
            self.device_index = device_index
            self.format = pyaudio.paInt16 # 16-bit int sampling
            self.SAMPLE_WIDTH = pyaudio.get_sample_size(self.format) # size of each sample
            self.SAMPLE_RATE = sample_rate # sampling rate in Hertz
            self.CHUNK = chunk_size # number of frames stored in each buffer

            self.audio = None
            self.stream = None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号