Recording Loopback ("What u hear") in Python using PyAudio

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

#record
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 40

HOST = '192.168.0.122'    # The remote host
PORT = 50007              # The same port as used by the server

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!

+4
source share
1 answer

EDIT: - . loopback Windows.

loopback, [1], . .

pyAudio :

>>> print p.get_device_count()
8

>>> print p.get_device_info_by_index(1)["name"]
Line 1 (Virtual Audio Cable)

, 1 device_index.

[1] http://virtual-audio-cable.en.softonic.com/

+1

Source: https://habr.com/ru/post/1538083/


All Articles