电脑麦克风扩音器

import pyaudio
import wave
from tqdm import tqdm

def record_audio():
	CHUNK = 256
	FORMAT = pyaudio.paInt16
	CHANNELS = 1
	RATE = 22500
	p = pyaudio.PyAudio()
	stream_in = p.open(format=FORMAT,
					channels=CHANNELS,
					rate=RATE,
					input=True,
					frames_per_buffer=CHUNK)
	stream_out = p.open(format=FORMAT,
					channels=CHANNELS,
					rate=RATE,
					output=True,
					frames_per_buffer=CHUNK)
	print("* recording")
	while True:
		data = stream_in.read(CHUNK)
		stream_out.write(data)
	print("* done recording")
	stream_in.stop_stream()
	stream_in.close()
	stream_out.stop_stream()
	stream_out.close()
	p.terminate()


record_audio()

可以调整CHUNK、CHANNELS、RATE来对延迟进行优化,实际上如果使用麦克风加上电脑外接屋子里面的小音响,扩音还是不错的,延迟挺低的。不过注意防止啸叫,麦克风需要离扬声器远一些。

猜你喜欢

转载自blog.csdn.net/uiop_uiop_uiop/article/details/108187748