Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyAudio: how to capture internal audio (not from microphone)?

Tags:

python

pyaudio

Tried like this:

p = pyaudio.PyAudio()

stream = p.open(format=FORMAT,
            channels=CHANNELS,
            rate=RATE,
            output=True,
            frames_per_buffer=chunk)

all = []
for i in range(0, int(RATE / chunk * RECORD_SECONDS)):
    data = stream.read(chunk)

but it throws paCanNotReadFromAnOutputOnlyStream
Using input=True it reads audio from mic, but that is not what I need.
Any help, please
Edit: I am using linux
I can also use other library, not only PyAudio. I just need to get this work

like image 303
AshFTW Avatar asked Oct 19 '25 06:10

AshFTW


1 Answers

Try this: https://github.com/intxcc/pyaudio_portaudio

PyAudio isn't made to record outputs, only inputs. This fork however introduces an api that gives you the ability to do so through loopback mode. To use this, set the flag as AUDCLNT_STREAMFLAGS_LOOPBACK. Hopefully this works and good luck!

like image 142
Liam Avatar answered Oct 21 '25 20:10

Liam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!