0

I have a python program that loops, playing audio files using python-sounddevice on an output device connected using dante virtual soundcard.

While playing the audio, if the network connection is suddenly lost, the program becomes completely unresponsive and freezes (the computer no longer has the output device available).

I have tried using a try/except to handle/catch a possible exception, but it seems that if this occurs during the audio playing, it does not raise any exception.

EDIT: Also, if reconnected to the network, the computer detects the output device again, but it doesn't help the issue.

Code:

import os
import sounddevice as sd
import soundfile as sf
import numpy
import time
import errno

if os.path.isfile(path) and os.access(path, os.R_OK):
    try:        
        data, fs = sf.read(path, dtype='float32')
        print('START')
        sd.play(data, fs, device = device_id)
        sd.wait()
        print('END') #never gets to this point
    except BaseException as err:
        print(err.args) 
else:
    raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), path)
mBAY
  • 1
  • 1
  • Sounds like a bug in `sounddevice` or the driver code (which, I assume, expects the device to come back). – AKX Jul 01 '20 at 19:14
  • If it freezes, I guess there isn't anything the `sounddevice` module can do. This sounds like an issue of PortAudio (you should probably ask on their mailing list: http://portaudio.com/contacts.html). What happens with other PortAudio programs, like e.g. Audacity? In case of a reconnect (if you can programmatically detect it?), you could try running `sd._terminate(); sd._initialize()`, see https://python-sounddevice.readthedocs.io/en/latest/api/expert-mode.html. – Matthias Jul 02 '20 at 07:37

0 Answers0