wire.py
568 Bytes
import sys
import pyaudio
RECORD_SECONDS = 5
CHUNK = 1024
RATE = 44100
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(2),
channels=1 if sys.platform == 'darwin' else 2,
rate=RATE,
input=True,
output=True,
frames_per_buffer=CHUNK)
print('* recording')
def add_echo(data, output_stream):
output_stream.write(data)
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
add_echo(stream.read(CHUNK), stream)
print('* done')
stream.close()
p.terminate()