Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sounddevice.PortAudioError: Error opening InputStream: Device unavailable [PaErrorCode -9985] #173

Open
demongolem opened this issue Feb 28, 2019 · 17 comments
Labels

Comments

@demongolem
Copy link

demongolem commented Feb 28, 2019

When trying to record, I use the line

myrecording = sd.rec(duration * fs, samplerate=fs, channels=2,dtype='float64')

This leads to

> Traceback (most recent call last):
  File "sd_test.py", line 7, in <module>
    myrecording = sd.rec(duration * fs, samplerate=fs, channels=2,dtype='float64')
  File "C:\Users\gwerner004\AppData\Local\Programs\Python\Python36\lib\site-packages\sounddevice.py", line 224, in rec
    ctx.input_dtype, callback, blocking, **kwargs)
  File "C:\Users\gwerner004\AppData\Local\Programs\Python\Python36\lib\site-packages\sounddevice.py", line 2417, in start_stream
    **kwargs)
  File "C:\Users\gwerner004\AppData\Local\Programs\Python\Python36\lib\site-packages\sounddevice.py", line 1301, in __init__
    **_remove_self(locals()))
  File "C:\Users\gwerner004\AppData\Local\Programs\Python\Python36\lib\site-packages\sounddevice.py", line 780, in __init__
    'Error opening {0}'.format(self.__class__.__name__))
  File "C:\Users\gwerner004\AppData\Local\Programs\Python\Python36\lib\site-packages\sounddevice.py", line 2572, in _check
    raise PortAudioError(errormsg, err)
sounddevice.PortAudioError: Error opening InputStream: Device unavailable [PaErrorCode -9985]

When I do python -m sounddevice I get this line:

>  1 Microphone (Plantronics C320), MME (2 in, 0 out)

Why would this device not be available for recording?

@demongolem
Copy link
Author

demongolem commented Feb 28, 2019

Upon further probing, even though the above line shows the headset microphone as the default and it is in fact the default for the Windows system I am using, the only device that works is

17 Jack Mic (Realtek HD Audio Front Mic input), Windows WDM-KS (2 in, 0 out)

If I used the plotline.py example for example which is in the repository and I unplug my headset, I see it run without error and pick up my voice.

Usually, I will have my headset plugged in so I can google hangout people online. It doesn't seem right that I have to try to find which device number is Jack Mic and then use that overwriting the default input device for my computer which works just fine on hangout.

@mgeier
Copy link
Member

mgeier commented Mar 1, 2019

The error message and the behavior you are describing are directly provided by the underlying PortAudio library. There is nothing I can do in the sounddevice module to change that, any changes would have to be done in PortAudio itself.

You should probably ask about this on the PortAudio mailing list: http://portaudio.com/contacts.html

@mgeier
Copy link
Member

mgeier commented Apr 2, 2019

@demongolem Are there any news on this issue?

@demongolem
Copy link
Author

No, I did report to PortAudio, but there has been no response on that.

@mgeier
Copy link
Member

mgeier commented Apr 4, 2019

OK, thanks for reporting this, could you please provide a link to the issue so we can follow it here?

@mgeier
Copy link
Member

mgeier commented Apr 8, 2019

Thanks for the link!

You would probably reach more people (including PortAudio users, not only core developers) when you ask on the mailing list.

Probably there is somebody else who could try the Plantronics C320 on Windows/MME?

I guess this is the device: https://www.plantronics.com/us/en/product/blackwire-310-320

And just to make sure: This problem only occurs with this one device, right?
Did you try other external USB devices?

@mgeier mgeier added the bug label Mar 18, 2020
@Ananthu27
Copy link

i have the same problem too .

@rkuchkarov
Copy link

I have this problem too

@mgeier
Copy link
Member

mgeier commented Jun 17, 2020

Did you ask on the PortAudio mailing list (http://portaudio.com/contacts.html)?

@csarami
Copy link

csarami commented Feb 18, 2021

I guess same error. I am also on MacMojave and try to play a sound file if a microphone signal goes above a threshold. I have :

import sounddevice as sd
import soundfile as sf
import numpy as np
duration = 5  # seconds


threshold = 30
filename = "./data/piano.wav"
data, fs = sf.read(filename, dtype='float32')  


def print_sound(indata, outdata, frames, time, status):
    if status:
        print(status)
    global threshold, data, fs
    volume_norm = 5*np.linalg.norm(indata)
    if volume_norm > threshold: 
        print("so loud!!!!")
        sd.play(data, fs)

with sd.Stream(callback=print_sound):
    sd.sleep(1000*duration)

When I run this the sound goes above the threshold, however, it cannot open the output Stream as follows;

$python3 main.py 
input underflow
input underflow
input underflow
so loud!!!!
so loud!!!!
input overflow, output underflow
so loud!!!!
input overflow, output underflow
so loud!!!!
||PaMacCore (AUHAL)|| Error on line 1316: err=''nope'', msg=Audio Hardware: Illegal Operation
From cffi callback <function _StreamBase.__init__.<locals>.callback_ptr at 0x10caf8680>:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sounddevice.py", line 881, in callback_ptr
    callback, idata, odata, frames, time, status)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sounddevice.py", line 2678, in _wrap_callback
    callback(*args)
  File "main.py", line 17, in print_sound
    sd.play(data, fs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sounddevice.py", line 177, in play
    **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 1489, 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 OutputStream: Internal PortAudio error [PaErrorCode -9986]

I have restarted my iMac ( Mojave) and still get the same error.

Any help would be much appreciated.

CS

@otori334
Copy link

I guess same error too. macOS Big Sur 11.5 beta, sounddevice 0.4.1.

# Used to convert waveform data into a 2-byte numeric sequence
import wave as wave
import numpy as np
import sounddevice as sd

#Sample files
sample_wave_file="./CMU_ARCTIC/cmu_us_aew_arctic/wav/arctic_a0001.wav"

#Load a file
wav=wave.open(sample_wave_file)

#Reads waveform data in PCM format
data=wav.readframes(wav.getnframes())

#Convert data to a 2-byte numeric string
data=np.frombuffer(data, dtype=np.int16)

#Playback data
sd.play(data,wav.getframerate())

status = sd.wait()

When I run this;

(.env) otori334@OTRMBP SSS % python3 /Users/otori334/GitHub/SSS/playback.py            
||PaMacCore (AUHAL)|| Error on line 1316: err='-66748', msg=Unknown Error
Traceback (most recent call last):
  File "/Users/otori334/GitHub/SSS/playback.py", line 20, in <module>
    sd.play(data,wav.getframerate())
  File "/Users/otori334/GitHub/SSS/.env/lib/python3.9/site-packages/sounddevice.py", line 174, in play
    ctx.start_stream(OutputStream, samplerate, ctx.output_channels,
  File "/Users/otori334/GitHub/SSS/.env/lib/python3.9/site-packages/sounddevice.py", line 2573, in start_stream
    self.stream = StreamClass(samplerate=samplerate,
  File "/Users/otori334/GitHub/SSS/.env/lib/python3.9/site-packages/sounddevice.py", line 1488, in __init__
    _StreamBase.__init__(self, kind='output', wrap_callback='array',
  File "/Users/otori334/GitHub/SSS/.env/lib/python3.9/site-packages/sounddevice.py", line 892, in __init__
    _check(_lib.Pa_OpenStream(self._ptr, iparameters, oparameters,
  File "/Users/otori334/GitHub/SSS/.env/lib/python3.9/site-packages/sounddevice.py", line 2738, in _check
    raise PortAudioError(errormsg, err)
sounddevice.PortAudioError: Error opening OutputStream: Internal PortAudio error [PaErrorCode -9986]

@otori334
Copy link

My problem was solved with this method #299

brew install portaudio --HEAD

Thanks

@staniko
Copy link

staniko commented Jan 29, 2022

stream.start() did the magic for me, before invoking stream.read().

@warrenarea
Copy link

warrenarea commented Oct 12, 2022

sounddevice.PortAudioError: Error opening RawStream: Unanticipated host error [PaErrorCode -9999]: 'Undefined external error.' [MME error 1]

I resolved this by enabling "Let apps access your microphone" in Windows 10/11.
a setting in Privacy & Security > Microphone

@joachimpoutaraud
Copy link

Uninstalling sounddevice from pip and reinstalling using conda worked for me

pip uninstall sounddevice
conda install -c conda-forge python-sounddevice

@bfalik
Copy link

bfalik commented May 9, 2023

Thank you, @warrenarea I tried it and now the problem is solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants