PortAudioError: Error opening Stream: Invalid number of channels [PaErrorCode -9998]

See original GitHub issue

i set Headphones as the input device and received that error

How can i set my headphones as device to record and then play the data from it to my mic?

I ran that on Windows 10, using PortAudio V19.6.0-devel

code:

with sd.Stream(device = (3,1),
                   samplerate=args.samplerate, blocksize=args.blocksize,
                   dtype=args.dtype, latency=args.latency, channels=2,
                   callback=callback)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
JonasRSVcommented, Oct 23, 2020

I am on ubuntu 18.04 and encountered the same exception.

I encountered this issue trying to record audio from a usb microphone: https://www.amazon.com/Newest-YOUMI-Microphone-Laptop-desktop/dp/B01MQ2AA0X/ref=sr_1_2?dchild=1&keywords=raspberry+pi+usb+microphone&qid=1603452930&sr=8-2.

Recording with alsa works fine, but using sounddevice raises

Expression 'paInvalidSampleRate' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2048
Expression 'PaAlsaStreamComponent_InitialConfigure( &self->capture, inParams, self->primeBuffers, hwParamsCapture, &realSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2719
Expression 'PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer, &inputLatency, &outputLatency, &hostBufferSizeMode )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2843
Traceback (most recent call last):
  File "/home/jonas/.cache/bazel/_bazel_jonas/f882173bb04895bcb83c04830ed51f60/execroot/__main__/bazel-out/k8-fastbuild/bin/friday/audio/keyword_detection/goldfish/preprocessing/record_personal_examples.runfiles/__main__/friday/audio/keyword_detection/goldfish/preprocessing/record_personal_examples.py", line 127, in <module>
    text=args.text)
  File "/home/jonas/.cache/bazel/_bazel_jonas/f882173bb04895bcb83c04830ed51f60/execroot/__main__/bazel-out/k8-fastbuild/bin/friday/audio/keyword_detection/goldfish/preprocessing/record_personal_examples.runfiles/__main__/friday/audio/keyword_detection/goldfish/preprocessing/record_personal_examples.py", line 32, in record_audio
    device=device, dtype="int16")
  File "/home/jonas/.local/lib/python3.6/site-packages/sounddevice.py", line 280, in rec
    ctx.input_dtype, callback, blocking, **kwargs)
  File "/home/jonas/.local/lib/python3.6/site-packages/sounddevice.py", line 2498, in start_stream
    **kwargs)
  File "/home/jonas/.local/lib/python3.6/site-packages/sounddevice.py", line 1382, in __init__
    **_remove_self(locals()))
  File "/home/jonas/.local/lib/python3.6/site-packages/sounddevice.py", line 861, in __init__
    'Error opening {0}'.format(self.__class__.__name__))
  File "/home/jonas/.local/lib/python3.6/site-packages/sounddevice.py", line 2653, in _check
    raise PortAudioError(errormsg, err)
sounddevice.PortAudioError: Error opening InputStream: Invalid sample rate [PaErrorCode -9997]

sounddevice works fine with my default speakers, but not the usb microphone, any clues on how to remedy this?

0reactions
mgeiercommented, Oct 26, 2020

Odd indeed …

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Pyaudio] Error: invalid number of channels -9998
I'd like to run this code that I got from this site and measure the loudness of a sound input from a mic....
Read more >
Error opening OutputStream: Invalid number of channels ...
play is interpreting this as a single sample with 4999 channels! Try transposing the array, so play sees the array as 4999 samples...
Read more >
python-sounddevice - Read the Docs
PortAudioError : Error opening InputStream: Invalid number of channels␣. ˓→[PaErrorCode -9998]. Please remember to provide the full command ...
Read more >
Contributing — python-sounddevice, version 0.4.1
PortAudioError : Error opening InputStream: Invalid number of channels [PaErrorCode -9998] ```. Please remember to provide the full command invocation and ...
Read more >
[Portaudio] Invalid number of channels...(?)
outputParameters.channelCount = 1; /* mono output */ The Pa_OpenStream fails with error code -9998, which means : "Invalid number of channels"
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found