rohsik2

init : making project

"""PyAudio Example: Audio wire between input and output. Callback version."""
import time
import sys
import pyaudio
import numpy as np
DURATION = 5 # seconds
delay_buffer = np.zeros((44100, 2), dtype=np.float32)
def callback(in_data, frame_count, time_info, status):
global delay_buffer
audio_data = np.frombuffer(in_data, dtype=np.float32).reshape(frame_count, 2)
delayed_data = np.concatenate((delay_buffer, audio_data))
delay_buffer = delayed_data[frame_count:]
return (audio_data + 0.5 * delay_buffer).tobytes(), pyaudio.paContinue
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(2),
channels=1,
rate=44100,
input=True,
output=True,
frames_per_buffer=1024,
stream_callback=callback)
start = time.time()
while stream.is_active() and (time.time() - start) < DURATION:
time.sleep(0.1)
stream.close()
p.terminate()
\ No newline at end of file
import pyaudio
import numpy as np
pa = pyaudio.PyAudio()
delay_buffer = np.zeros((44100, 2), dtype=np.float32)
def callback(in_data, frame_count, time_info, status):
global delay_buffer
audio_data = np.frombuffer(in_data, dtype=np.float32).reshape(frame_count, 2)
delayed_data = np.concatenate((delay_buffer, audio_data))
delay_buffer = delayed_data[frame_count:]
return (audio_data + 0.5 * delay_buffer).tobytes(), pyaudio.paContinue
RATE = 44100
CHUNK = 1024
stream = pa.open(format=pyaudio.paFloat32,
channels=1,
rate=RATE,
input=True,
output=True,
frames_per_buffer=CHUNK,
stream_callback=callback)
stream.start_stream()
# keep the stream running for a few seconds
for i in range(0, int(RATE / CHUNK * 30)):
stream.write(stream.read(CHUNK))
stream.stop()
stream.close()
pa.terminate()
No preview for this file type
import numpy as np
import pyaudio
import time
pa = pyaudio.PyAudio()
delay_buffer = np.zeros((44100, 1), dtype=np.float32)
def callback(in_data, frame_count, time_info, status):
global delay_buffer
audio_data = np.frombuffer(in_data, dtype=np.float32).reshape(1024, 1)
delayed_data = np.concatenate((delay_buffer, audio_data))
delay_buffer = delayed_data[frame_count:]
return (audio_data + 0.5 * delay_buffer).tobytes(), pyaudio.paContinue
stream = pa.open(format=pyaudio.paFloat32,
channels=1,
rate=1024,
input=True,
output=True,
frames_per_buffer=44100,
stream_callback=callback)
start = time.time()
DURATION = 30
# keep the stream running for a few seconds
while stream.is_active() and (time.time() - start) < DURATION:
time.sleep(0.1)
stream.stop()
stream.close()
pa.terminate()
\ No newline at end of file
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()
\ No newline at end of file