danilobellini / audiolazy

Expressive Digital Signal Processing (DSP) package for Python
GNU General Public License v3.0
689 stars 74 forks source link

"OSError: [Errno -9985] Device unavailable" #4

Open Nel-Fie opened 7 years ago

Nel-Fie commented 7 years ago

While trying to use the I/O wire example provided with the master (iowire.py) with any other audio API than the default, I always get this error (in PyCharm CE, W7 x64 with Python 3.5.1)): (The [...]'s are redactions on my path, the actual traceback contains the full path.)_

Traceback (most recent call last):
  File "C:/[...]/audiolazy_master/examples/io_wire.py", line 46, in <module>
    pr.play(pr.record())
  File "C:\[...]\lib\site-packages\audiolazy\lazy_io.py", line 270, in play
    new_thread = AudioThread(self, audio, **kwargs)
  File "C:\[...]\lib\site-packages\audiolazy\lazy_io.py", line 401, in __init__
    **kwargs)
  File "C:\[...]\lib\site-packages\pyaudio.py", line 750, in open
    stream = Stream(self, *args, **kwargs)
  File "C:\[...]\lib\site-packages\pyaudio.py", line 441, in __init__
    self._stream = pa.open(**arguments)
OSError: [Errno -9985] Device unavailable

Process finished with exit code 1

Here is the modified script for the wire:

[...]
from audiolazy import chunks, AudioIO
import sys

# Choose API via command-line
api = sys.argv[1] if sys.argv[1:] else None
print(api)

# Amount of samples per chunk to be sent to PortAudio
chunks.size = 1 if api == "jack" else 16

with AudioIO(True, api="asio") as pr: # A player-recorder
  pr.play(pr.record())

When using the I/O wire example provided with the PyAudio master (PyAudio-0.2.9.tar/test/wire_full.py), the wire works perfectly fine, the ASIO device is detected and the wire established. Here is the script, with the index of my ASIO device being 12:

import pyaudio
import sys

CHUNK = 256
WIDTH = 2
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5

if sys.platform == 'darwin':
    CHANNELS = 1

p = pyaudio.PyAudio()

stream = p.open(format=p.get_format_from_width(WIDTH),
                channels=CHANNELS,
                rate=RATE,
                input=True,
                input_device_index=12,
                output_device_index=12,
                output=True,
                frames_per_buffer=CHUNK)

print("* recording")

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
    data = stream.read(CHUNK)
    stream.write(data, CHUNK)

print("* done")

stream.stop_stream()
stream.close()

p.terminate()

Here's the info for the device, as given by as given by p.get_device_info_by_index(12):

{'defaultLowInputLatency': 0.0014512471655328798, 'name': 'Yamaha Steinberg USB ASIO', 'defaultHighInputLatency': 0.0014512471655328798, 'index': 12, 'structVersion': 2, 'maxOutputChannels': 2, 'defaultLowOutputLatency': 0.0014512471655328798, 'maxInputChannels': 2, 'defaultHighOutputLatency': 0.0014512471655328798, 'hostApi': 2, 'defaultSampleRate': 44100.0}

Sorry if it it's a PICNIC.

danilobellini commented 7 years ago

Thanks for reporting this! Have you tried with api="yamaha" instead of api="asio"? What are the device names for the remaining indices?

Nel-Fie commented 7 years ago

Thank you for your swift answer!

I've tried your suggestion. Unfortunately, I get the standard "api not found" exception, as follows:

Traceback (most recent call last):
  File "C:\[...]\lib\site-packages\audiolazy\lazy_io.py", line 196, in __init__
    self.api = next(el for el in apis_gen
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/[...]/audiolazy_master/examples/io_wire.py", line 45, in <module>
    with AudioIO(True, api="yamaha") as pr: # A player-recorder
  File "C:\[...]\lib\site-packages\audiolazy\lazy_io.py", line 199, in __init__
    raise RuntimeError("API '{}' not found".format(api))
RuntimeError: API 'yamaha' not found

Process finished with exit code 1

As for other devices, here is what PyAudio spits out:

{'defaultLowInputLatency': 0.09, 'structVersion': 2, 'maxOutputChannels': 0, 'index': 0, 'defaultHighInputLatency': 0.18, 'defaultLowOutputLatency': 0.09, 'name': 'Microsoft Soundmapper - Input', 'defaultHighOutputLatency': 0.18, 'maxInputChannels': 2, 'defaultSampleRate': 44100.0, 'hostApi': 0}
{'defaultLowInputLatency': 0.09, 'structVersion': 2, 'maxOutputChannels': 0, 'index': 1, 'defaultHighInputLatency': 0.18, 'defaultLowOutputLatency': 0.09, 'name': 'Line (Steinberg CI1)', 'defaultHighOutputLatency': 0.18, 'maxInputChannels': 2, 'defaultSampleRate': 44100.0, 'hostApi': 0}
{'defaultLowInputLatency': 0.09, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 2, 'defaultHighInputLatency': 0.18, 'defaultLowOutputLatency': 0.09, 'name': 'Microsoft Soundmapper - Output', 'defaultHighOutputLatency': 0.18, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 0}
{'defaultLowInputLatency': 0.09, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 3, 'defaultHighInputLatency': 0.18, 'defaultLowOutputLatency': 0.09, 'name': 'Line (Steinberg CI1)', 'defaultHighOutputLatency': 0.18, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 0}
{'defaultLowInputLatency': 0.09, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 4, 'defaultHighInputLatency': 0.18, 'defaultLowOutputLatency': 0.09, 'name': 'Digitalaudio (S/PDIF) (High Def', 'defaultHighOutputLatency': 0.18, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 0}
{'defaultLowInputLatency': 0.09, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 5, 'defaultHighInputLatency': 0.18, 'defaultLowOutputLatency': 0.09, 'name': 'Digitalaudio (S/PDIF) (High Def', 'defaultHighOutputLatency': 0.18, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 0}
{'defaultLowInputLatency': 0.12, 'structVersion': 2, 'maxOutputChannels': 0, 'index': 6, 'defaultHighInputLatency': 0.24, 'defaultLowOutputLatency': 0.0, 'name': 'Primärer Soundaufnahmetreiber', 'defaultHighOutputLatency': 0.0, 'maxInputChannels': 2, 'defaultSampleRate': 44100.0, 'hostApi': 1}
{'defaultLowInputLatency': 0.12, 'structVersion': 2, 'maxOutputChannels': 0, 'index': 7, 'defaultHighInputLatency': 0.24, 'defaultLowOutputLatency': 0.0, 'name': 'Line (Steinberg CI1)', 'defaultHighOutputLatency': 0.0, 'maxInputChannels': 2, 'defaultSampleRate': 44100.0, 'hostApi': 1}
{'defaultLowInputLatency': 0.0, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 8, 'defaultHighInputLatency': 0.0, 'defaultLowOutputLatency': 0.12, 'name': 'Primärer Soundtreiber', 'defaultHighOutputLatency': 0.24, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 1}
{'defaultLowInputLatency': 0.0, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 9, 'defaultHighInputLatency': 0.0, 'defaultLowOutputLatency': 0.12, 'name': 'Line (Steinberg CI1)', 'defaultHighOutputLatency': 0.24, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 1}
{'defaultLowInputLatency': 0.0, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 10, 'defaultHighInputLatency': 0.0, 'defaultLowOutputLatency': 0.12, 'name': 'Digitalaudio (S/PDIF) (High Definition Audio-Gerät)', 'defaultHighOutputLatency': 0.24, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 1}
{'defaultLowInputLatency': 0.0, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 11, 'defaultHighInputLatency': 0.0, 'defaultLowOutputLatency': 0.12, 'name': 'Digitalaudio (S/PDIF) (High Definition Audio-Gerät)', 'defaultHighOutputLatency': 0.24, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 1}
{'defaultLowInputLatency': 0.0014512471655328798, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 12, 'defaultHighInputLatency': 0.0014512471655328798, 'defaultLowOutputLatency': 0.0014512471655328798, 'name': 'Yamaha Steinberg USB ASIO', 'defaultHighOutputLatency': 0.0014512471655328798, 'maxInputChannels': 2, 'defaultSampleRate': 44100.0, 'hostApi': 2}
{'defaultLowInputLatency': 0.005011337868480726, 'structVersion': 2, 'maxOutputChannels': 0, 'index': 13, 'defaultHighInputLatency': 0.02, 'defaultLowOutputLatency': 0.005011337868480726, 'name': 'ZOOM H and F Series ASIO', 'defaultHighOutputLatency': 0.02, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 2}
{'defaultLowInputLatency': 0.0, 'structVersion': 2, 'maxOutputChannels': 0, 'index': 14, 'defaultHighInputLatency': 0.0, 'defaultLowOutputLatency': 0.0, 'name': 'ZOOM H and F Series Multi ASIO', 'defaultHighOutputLatency': 0.0, 'maxInputChannels': 0, 'defaultSampleRate': 0.0, 'hostApi': 2}
{'defaultLowInputLatency': 0.0, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 15, 'defaultHighInputLatency': 0.0, 'defaultLowOutputLatency': 0.003, 'name': 'Line (Steinberg CI1)', 'defaultHighOutputLatency': 0.01, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 3}
{'defaultLowInputLatency': 0.0, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 16, 'defaultHighInputLatency': 0.0, 'defaultLowOutputLatency': 0.003, 'name': 'Digitalaudio (S/PDIF) (High Definition Audio-Gerät)', 'defaultHighOutputLatency': 0.0101587, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 3}
{'defaultLowInputLatency': 0.0, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 17, 'defaultHighInputLatency': 0.0, 'defaultLowOutputLatency': 0.003, 'name': 'Digitalaudio (S/PDIF) (High Definition Audio-Gerät)', 'defaultHighOutputLatency': 0.0101587, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 3}
{'defaultLowInputLatency': 0.003, 'structVersion': 2, 'maxOutputChannels': 0, 'index': 18, 'defaultHighInputLatency': 0.01, 'defaultLowOutputLatency': 0.0, 'name': 'Line (Steinberg CI1)', 'defaultHighOutputLatency': 0.0, 'maxInputChannels': 2, 'defaultSampleRate': 44100.0, 'hostApi': 3}
{'defaultLowInputLatency': 0.01, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 19, 'defaultHighInputLatency': 0.04, 'defaultLowOutputLatency': 0.01, 'name': 'SPDIF Out (HD Audio-SPDIF-Ausgabe 5)', 'defaultHighOutputLatency': 0.04, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 4}
{'defaultLowInputLatency': 0.01, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 20, 'defaultHighInputLatency': 0.04, 'defaultLowOutputLatency': 0.01, 'name': 'SPDIF Out (HD Audio-SPDIF-Ausgabe)', 'defaultHighOutputLatency': 0.04, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 4}
{'defaultLowInputLatency': 0.01, 'structVersion': 2, 'maxOutputChannels': 0, 'index': 21, 'defaultHighInputLatency': 0.08533333333333333, 'defaultLowOutputLatency': 0.01, 'name': 'Line (Steinberg CI1)', 'defaultHighOutputLatency': 0.08533333333333333, 'maxInputChannels': 2, 'defaultSampleRate': 44100.0, 'hostApi': 4}
{'defaultLowInputLatency': 0.01, 'structVersion': 2, 'maxOutputChannels': 2, 'index': 22, 'defaultHighInputLatency': 0.08533333333333333, 'defaultLowOutputLatency': 0.01, 'name': 'Line (Steinberg CI1)', 'defaultHighOutputLatency': 0.08533333333333333, 'maxInputChannels': 0, 'defaultSampleRate': 44100.0, 'hostApi': 4}

If it helps, here are the available host api's, also according to PyAudio:

{'structVersion': 1, 'deviceCount': 6, 'index': 0, 'defaultInputDevice': 1, 'name': 'MME', 'defaultOutputDevice': 3, 'type': 2}
{'structVersion': 1, 'deviceCount': 6, 'index': 1, 'defaultInputDevice': 6, 'name': 'Windows DirectSound', 'defaultOutputDevice': 8, 'type': 1}
{'structVersion': 1, 'deviceCount': 3, 'index': 2, 'defaultInputDevice': 12, 'name': 'ASIO', 'defaultOutputDevice': 12, 'type': 3}
{'structVersion': 1, 'deviceCount': 4, 'index': 3, 'defaultInputDevice': 18, 'name': 'Windows WASAPI', 'defaultOutputDevice': 15, 'type': 13}
{'structVersion': 1, 'deviceCount': 4, 'index': 4, 'defaultInputDevice': 21, 'name': 'Windows WDM-KS', 'defaultOutputDevice': 22, 'type': 11}

For good measure, I've tried those that aren't ASIO. MME works, Windows DirectSound is mute but does not raise an exception, Windows WASAPI works (distorted/downsampled sound, though), while Windows WDM-KS raises the following exception:

Traceback (most recent call last):
  File "C:/[...]/audiolazy_master/examples/io_wire.py", line 48, in <module>
    pr.play(pr.record())
  File "C:/[...]\lib\site-packages\audiolazy\lazy_io.py", line 328, in record
    **kwargs),
  File "C:/[...]\lib\site-packages\pyaudio.py", line 750, in open
    stream = Stream(self, *args, **kwargs)
  File "C:/[...]\lib\site-packages\pyaudio.py", line 441, in __init__
    self._stream = pa.open(**arguments)
OSError: [Errno -9999] Unanticipated host error

Sorry if I missed anything, or if something I wrote is obvious. I'm still a novice to python and I never had to worry about audio APIs outside of the context of DAWs until now.

ipieren commented 4 years ago

Hello! This generally happens if your microphone is being used by some other device. Just check the applications that are currently using your microphone or some other input device.

ravurip commented 4 years ago

Hello! I'm facing the same issue on raspberry pi.

Expression 'ret' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1736 Expression 'AlsaOpen( &alsaApi->baseHostApiRep, params, streamDir, &self->pcm )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1904 Expression 'PaAlsaStreamComponent_Initialize( &self->capture, alsaApi, inParams, StreamDirection_In, NULL != callback )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2171 Expression 'PaAlsaStream_Initialize( stream, alsaHostApi, inputParameters, outputParameters, sampleRate, framesPerBuffer, callback, streamFlags, userData )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2840 Traceback (most recent call last): File "", line 4, in File "/usr/lib/python3/dist-packages/pyaudio.py", line 750, in open stream = Stream(self, *args, kwargs) File "/usr/lib/python3/dist-packages/pyaudio.py", line 441, in init self._stream = pa.open(arguments) OSError: [Errno -9985] Device unavailable

Below is the microphone info, as read by the pyaudio input device info.

 >>>p.get_default_input_device_info()
{'index': 2, 'structVersion': 2, 'name': 'USB PnP Sound Device: Audio (hw:1,0)', 'hostApi': 0, 'maxInputChannels': 1, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.008684807256235827, 'defaultLowOutputLatency': -1.0, 'defaultHighInputLatency': 0.034829931972789115, 'defaultHighOutputLatency': -1.0, 'defaultSampleRate': 44100.0}

Can somebody please let me know what I'm missing here.

rudrathegreat commented 3 years ago

Same here, even though nothing is using my mic