i trying realtime player/recorder looper. i´m starting , dealing win pyaudio.
at moment, able create stream , store in numpy array, not able send pyaudio stream when want.
i want use arrays because prefer store in memory until want save wave files.
note try play matth´s python-sounddevice, i'm not able play it. can't find way achieve this.
here´s current code:
import sys import pyaudio import numpy np import sounddevice sd p = pyaudio.pyaudio() datos_numpy=np.array([]) chunk=64 channels=2 format=pyaudio.pafloat32 rate=44100 is_recording=false is_playing=false def callback(in_data, frame_count, time_info, status): global datos_numpy, is_playing, is_recording if is_recording==true: if in_data: print 'recording' temp_data=np.fromstring(in_data, dtype=np.float32) datos_numpy = np.append(datos_numpy,temp_data) else: print('no input') return in_data, pyaudio.pacontinue elif is_playing==true: print 'playing' #out_data= ???? here problem #return out_data, pyaudio.pacontinue else: return in_data, pyaudio.pacontinue stream = p.open(format=pyaudio.pafloat32, channels=channels, rate=rate, output=true, input=true, input_device_index=6, output_device_index=14, frames_per_buffer=chunk, stream_callback=callback) def record(): global is_playing, is_recording is_recording=true is_playing=false def play(): global is_playing, is_recording, datos_numpy is_recording=false is_playing=true sd.play(datos_numpy, 44100)
since getting numpy array fromstring
method, may able toget string buffer numpy.tostring()
method.
alternatively, instead of converting numpy array, can pickle string buffer hard disk. not have worry how working buffer back.
Comments
Post a Comment