__init__.py 文件源码

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

项目:Spherical-robot 作者: Evan-Zhao 项目源码 文件源码
def record(record_len):  # in second
    if p is None or idx is None:
        init()

    # Constant area. These are put inside because this function will not be in main thread.
    channels = 6
    rate = 48000
    chunk = 1200
    # Bit depth and max value goes together.
    record_format, numpy_format = pyaudio.paInt32, numpy.int32

    stream = p.open(format=record_format,
                    channels=channels,
                    rate=rate,
                    input=True,
                    input_device_index=idx,
                    frames_per_buffer=chunk)
    print('Begin recording...')
    wave_data = numpy.empty((channels, 0), dtype=numpy_format)
    for i in range(0, int(rate / chunk * record_len)):
        data = stream.read(chunk, exception_on_overflow=False)
        np_tmp = numpy.frombuffer(data, dtype=numpy_format)
        np_tmp = numpy.reshape(np_tmp, (chunk, channels))
        np_tmp = np_tmp.transpose()
        wave_data = numpy.append(wave_data, np_tmp, axis=1)
    stream.stop_stream()
    stream.close()
    return rate, wave_data, pos
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号