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

Unable to run example given on README [sounddevice.PortAudioError] #116

Closed
ankurdhuriya opened this issue Jan 12, 2023 · 4 comments
Closed
Labels
bug Something isn't working
Milestone

Comments

@ankurdhuriya
Copy link

>>> from diart import OnlineSpeakerDiarization
>>> from diart.sources import MicrophoneAudioSource
>>> from diart.inference import RealTimeInference
>>> from diart.sinks import RTTMWriter
>>> pipeline = OnlineSpeakerDiarization()
>>> pipeline.config
<diart.blocks.diarization.PipelineConfig object at 0x16f5909d0>
>>> pipeline.config.sample_rate
16000
>>> pipeline = OnlineSpeakerDiarization()
KeyboardInterrupt
>>> mic = MicrophoneAudioSource(pipeline.config.sample_rate)
||PaMacCore (AUHAL)|| AUHAL component not found.Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ankurdhuriya/opt/miniconda3/envs/diart/lib/python3.8/site-packages/diart/sources.py", line 125, in __init__
    self._mic_stream = sd.InputStream(
  File "/Users/ankurdhuriya/opt/miniconda3/envs/diart/lib/python3.8/site-packages/sounddevice.py", line 1421, in __init__
    _StreamBase.__init__(self, kind='input', wrap_callback='array',
  File "/Users/ankurdhuriya/opt/miniconda3/envs/diart/lib/python3.8/site-packages/sounddevice.py", line 898, in __init__
    _check(_lib.Pa_OpenStream(self._ptr, iparameters, oparameters,
  File "/Users/ankurdhuriya/opt/miniconda3/envs/diart/lib/python3.8/site-packages/sounddevice.py", line 2745, in _check
    raise PortAudioError(errormsg, err, hosterror_info)
sounddevice.PortAudioError: <exception str() failed>

portaudio==19.7.0
sounddevice==0.4.5

Platform, Operating System, and Programming Language

Platform : Apple M2
OS : macOS Ventura 13.1
Programming Language : Python 3.8.15

@juanmc2005
Copy link
Owner

Hi @ankurdhuriya,

I don't have an apple device to verify it, but I suspect this may be related to issue #99.
Could you try modifying MicrophoneAudioSource to manually set the correct device ID ?

You can view the available devices with python -m sounddevice

@juanmc2005 juanmc2005 added bug Something isn't working unclear The exact nature of the issue is not clear until further information is provided labels Jan 19, 2023
@juanmc2005
Copy link
Owner

I think I may have a temporary solution to this. Diart provides a TorchStreamAudioSource that you could use to wrap a torchaudio.io.StreamReader linked to the microphone as shown here:

from torchaudio.io import StreamReader
from diart import OnlineSpeakerDiarization
from diart.sources import TorchStreamAudioSource
from diart.inference import RealTimeInference
from diart.sinks import RTTMWriter

pipeline = OnlineSpeakerDiarization()
streamer = StreamReader("0:0", format="avfoundation")
mic = TorchStreamAudioSource(
    uri="live_recording",
    sample_rate=pipeline.config.sample_rate,
    streamer=streamer,
    stream_index=0,
)
inference = RealTimeInference(pipeline, mic, do_plot=True)
inference.attach_observers(RTTMWriter(mic.uri, "/output/file.rttm"))
prediction = inference()

This should automatically grab the Mac's default microphone.
Ideally I would like to have a single class for any device, but a new AppleMicrophoneAudioSource could be a nice temporary solution to quickly get started with the default device.
I would gladly merge a PR with this feature if you're interested in contributing.

@juanmc2005 juanmc2005 removed the unclear The exact nature of the issue is not clear until further information is provided label Jan 19, 2023
@juanmc2005 juanmc2005 added this to the Version 0.7 milestone Jan 19, 2023
@juanmc2005
Copy link
Owner

Implemented in #182. Will appear in next release (v0.8).

Feel free to reopen if needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants