用pyaudio录制单个频道

时间:2019-06-19 12:42:57

标签: linux python-2.7 alsa pyaudio

我只想录制我的麦克风阵列的第5个通道。

我想在运行带有python 2.7的gentoo linux的linux设备上执行此操作。

我已经尝试过的是录制5个通道,然后将第5个通道拆分出来。

可以,但是会减慢处理速度。

CHUNK = 1024
BUF_MAX_SIZE = CHUNK * 10
q = Queue(maxsize=int(round(BUF_MAX_SIZE / CHUNK)))

audio_source = AudioSource(q, True, True)

FORMAT = pyaudio.paInt16
CHANNELS = 5  # All channels to be recorded
CHANNEL = 5  # single channel to be processed
RATE = 16000

def pyaudio_callback(in_data, frame_count, time_info, status):
    try:
        in_data = in_data[CHANNEL-1::CHANNELS]
        q.put(in_data)
    except Full:
        pass # discard
    return (None, pyaudio.paContinue)  

stream = audio.open(
    format=FORMAT,
    channels=CHANNELS,
    rate=RATE,
    input=True,
    frames_per_buffer=CHUNK,
    stream_callback=pyaudio_callback,
    start=False
)

stream.start_stream()

是否可以只从我的输入设备录制特定频道?

0 个答案:

没有答案