python-sounddevice
python-sounddevice copied to clipboard
sounddevice.PortAudioError: Error opening InputStream: Invalid number of channels [PaErrorCode -9998]
I get the follow errer when I run sounddevice. Could anybody show me how to make it work?
My OS is Mac OS X 10.15.6.
$ cat main.py
#!/usr/bin/env python3
# vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8:
import sounddevice
fs = 44100
seconds = 10
myrecording = sounddevice.rec(int(seconds * fs), samplerate=fs, channels=2)
import wave
obj = wave.open('sound.wav', 'w')
obj.setnchannels(1) # mono
obj.setsampwidth(2)
obj.setframerate(fs)
obj.writeframesraw(myrecording)
sounddevice.wait()
$ ./main.py
Traceback (most recent call last):
File "./main.py", line 7, in <module>
myrecording = sounddevice.rec(int(seconds * fs), samplerate=fs, channels=2)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sounddevice.py", line 275, in rec
ctx.input_dtype, callback, blocking, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sounddevice.py", line 2578, in start_stream
**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sounddevice.py", line 1416, in __init__
**_remove_self(locals()))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sounddevice.py", line 895, in __init__
'Error opening {}'.format(self.__class__.__name__))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sounddevice.py", line 2738, in _check
raise PortAudioError(errormsg, err)
sounddevice.PortAudioError: Error opening InputStream: Invalid number of channels [PaErrorCode -9998]
Duplicate of #303?