使用PyAudio在Python中进行回送(“您听到的内容")记录 [英] Loopback ('What u hear') recording in Python using PyAudio

查看:267
本文介绍了使用PyAudio在Python中进行回送(“您听到的内容")记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,

我正在尝试使用PyAudio使用Python记录我的扬声器输出. 目前,我可以记录我的麦克风输入并将其发送到监听器". 我现在想做的是创建一个环回,因此它将记录我扬声器的输出. 我可以使用Windows中的立体声混音"来做到这一点,但是由于这需要跨平台,因此应该有另一种方式.

I'm trying to record my speaker output with Python using PyAudio. Currently, I'm able to record my microphone input and send this over to the 'listener'. What I'm trying to do now is create a loopback, so it will record the output from my speakers. I was able to do this with the 'Stereo Mix' from windows, but since this needs to be cross platform, there should be another way to do this.

有人对我如何实现这一目标有任何建议吗?

Does anyone has some advice on how I could achieve this?

这是我当前用于记录输入流的代码.

Here is my current code for recording an 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")

任何帮助将不胜感激!

推荐答案

我没有看到跨平台的东西.留作Windows环回设备的参考.

I didn't see the cross-platform thing. Leaving this as a reference to the loopback device for Windows.

安装虚拟环回设备,例如[1],然后选择适配器作为输入设备.那对我很好.

Install a virtual loopback device like [1] and select the adapter as your input device. That works for me very well.

您可以使用pyAudio进行检查,如下所示:

You can check that with pyAudio like so:

>>> print p.get_device_count()
8

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

因此,我使用1作为我的device_index.

So, I use 1 as my device_index.

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

这篇关于使用PyAudio在Python中进行回送(“您听到的内容")记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆