Friday 15 May 2015

python - Record speakers output with PyAudio -



python - Record speakers output with PyAudio -

i'm trying record ouput computer speakers pyaudio. tried modify code illustration given in pyaudio documentation, doesn't work. here's code:

import pyaudio import wave chunk = 1024 format = pyaudio.paint16 channels = 2 rate = 44100 record_seconds = 5 wave_output_filename = "output.wav" p = pyaudio.pyaudio() speakers = p.get_default_output_device_info()["hostapi"] #the part have modified stream = p.open(format=format, channels=channels, rate=rate, input=true, frames_per_buffer=chunk, input_host_api_specific_stream_info=speakers) #the part have modified print("* recording") frames = [] in range(0, int(rate / chunk * record_seconds)): info = stream.read(chunk) frames.append(data) print("* done recording") stream.stop_stream() stream.close() p.terminate() wf = wave.open(wave_output_filename, 'wb') wf.setnchannels(channels) wf.setsampwidth(p.get_sample_size(format)) wf.setframerate(rate) wf.writeframes(b''.join(frames)) wf.close()

could help me please?

you can't record output stream though input. record, need connect pyaudio input device, microphone. @ to the lowest degree that's normal way things.

try connecting microphone first, , see if anything. if works, seek doing unusual.

as little speedup iterations, rather recording , looking @ file, it's easier print out max few chunks create sure you're bringing in data. watching numbers scroll , comparing them sound gives quick estimate of whether things correctly connected.

import audioop mx = audioop.max(data, 2) print mx

python pyaudio

No comments:

Post a Comment