i want to record my system audio with pyaudio (in python) but i'm getting this error : OSError: [Errno -9996] Invalid input device (no default output device) please help me. here is my 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()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("* recording")
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = 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()
here is full stacktrace :
C:\jagdish\JKRecorder> & C:/Users/mohit/AppData/Local/Programs/Python/Python39/python.exe c:/jagdish/JKRecorder/temp.py
Traceback (most recent call last):
File "c:\jagdish\JKRecorder\temp.py", line 13, in <module>
stream = p.open(format=FORMAT,
File "C:\Users\mohit\AppData\Local\Programs\Python\Python39\lib\site-packages\pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "C:\Users\mohit\AppData\Local\Programs\Python\Python39\lib\site-packages\pyaudio.py", line 441, in __init__
self._stream = pa.open(**arguments)
OSError: [Errno -9996] Invalid input device (no default output device)
C:\jagdish\JKRecorder>