Good afternoon,
I am trying to record my speaker using Python using PyAudio. Currently, I can record my microphone input and pass it to the “listener”. What I'm trying to do now is create a loopback so that it records the output from my speakers. I was able to do this using the "Stereo Mix" from the windows, but since this should be a cross platform, there must be another way to do this.
Does anyone have any tips on how I can achieve this?
Here is my current code for recording the input stream.
import socket
import pyaudio
import wave
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 40
HOST = '192.168.0.122'
PORT = 50007
recording = True
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
p = pyaudio.PyAudio()
for i in range(0, p.get_device_count()):
print(i, p.get_device_info_by_index(i)['name'])
device_index = int(input('Device index: '))
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK,
input_device_index=device_index)
print("*recording")
frames = []
while recording:
data = stream.read(CHUNK)
frames.append(data)
s.sendall(data)
print("*done recording")
stream.stop_stream()
stream.close()
p.terminate()
s.close()
print("*closed")
Any help would be greatly appreciated!
source
share