1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| import pyaudio
import wave
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5#limite le temps de capture
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
p2 = pyaudio.PyAudio()
stream_lecture = p2.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
output=True)
print("* début capture")
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):#si vous voulez une diffusion sans limite de temps, boucle while infinie
data = stream.read(CHUNK)
stream_lecture.write(data)
print("* capture terminée")
stream.stop_stream()
stream.close()
p.terminate()
stream_lecture.stop_stream()
stream_lecture.close()
p2.terminate() |
Partager