Created
February 4, 2014 00:45
-
-
Save fwaechter/8795472 to your computer and use it in GitHub Desktop.
PyAudio Example: Make a wire between input and output (i.e., record a few samples and play them back immediately).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
PyAudio Example: Make a wire between input and output (i.e., record a | |
few samples and play them back immediately). | |
This is the callback (non-blocking) version. | |
""" | |
import pyaudio | |
import time | |
WIDTH = 2 | |
CHANNELS = 2 | |
RATE = 44100 | |
p = pyaudio.PyAudio() | |
def callback(in_data, frame_count, time_info, status): | |
return (in_data, pyaudio.paContinue) | |
stream = p.open(format=p.get_format_from_width(WIDTH), | |
channels=CHANNELS, | |
rate=RATE, | |
input=True, | |
output=True, | |
stream_callback=callback) | |
stream.start_stream() | |
while stream.is_active(): | |
time.sleep(0.1) | |
stream.stop_stream() | |
stream.close() | |
p.terminate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment