Skip to content

Instantly share code, notes, and snippets.

@sudofox
Created March 28, 2024 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudofox/6c3910d6c63950b57d59534923ec7527 to your computer and use it in GitHub Desktop.
Save sudofox/6c3910d6c63950b57d59534923ec7527 to your computer and use it in GitHub Desktop.
Plays audio from mic over speaker
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