Created
March 28, 2024 16:15
-
-
Save sudofox/6c3910d6c63950b57d59534923ec7527 to your computer and use it in GitHub Desktop.
Plays audio from mic over speaker
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
import pyaudio | |
import wave | |
import sys | |
CHUNK = 1024 | |
FORMAT = pyaudio.paInt16 | |
CHANNELS = 1 | |
RATE = 44100 | |
def main(): | |
p = pyaudio.PyAudio() | |
stream = p.open(format=FORMAT, | |
channels=CHANNELS, | |
rate=RATE, | |
input=True, | |
output=True, | |
frames_per_buffer=CHUNK) | |
print("Streaming audio. Press Ctrl+C to stop.") | |
try: | |
while True: | |
data = stream.read(CHUNK) | |
stream.write(data, CHUNK) | |
except KeyboardInterrupt: | |
print("\nStopping...") | |
stream.stop_stream() | |
stream.close() | |
p.terminate() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment