I’m using elevenlabs API to stream an audio response. It requires MPV (which I’ve put into packages.txt). Unfortunately, the mpv subprocess is unable to locate an audio device on Streamlit Cloud, evidenced by the stderr output:
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'\nALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory\nALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings\nALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory\nALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name\nALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory\nALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory\nALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM default\nCannot connect to server socket err = No such file or directory\nCannot connect to server request channel\njack server is not running or cannot be started\nJackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock\nJackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock\nALSA lib confmisc.c:767:(parse_card) cannot find card '0'\nALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory\nALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings\nALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory\nALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name\nALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory\nALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory\nALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM default\nALSA lib pcm_hw.c:1829:(_snd_pcm_hw_open) Invalid value for card\ncouldn't open play stream: No such file or directory\n
Specifically, this issue occurs within the following function:
def stream(audio_stream: Iterator[bytes]) -> bytes:
if not is_installed("mpv"):
message = (
"mpv not found, necessary to stream audio. "
"On mac you can install it with 'brew install mpv'. "
"On linux and windows you can install it from https://mpv.io/"
)
raise ValueError(message)
mpv_command = ["mpv", "--no-cache", "--no-terminal", "--", "fd://0"]
mpv_process = subprocess.Popen(
mpv_command,
stdin=subprocess.PIPE,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE
)
audio = b""
for chunk in audio_stream:
if chunk is not None:
mpv_process.stdin.write(chunk) # ISSUE HERE
mpv_process.stdin.flush()
audio += chunk
if mpv_process.stdin:
mpv_process.stdin.close()
mpv_process.wait()
return audio
Any ideas on how to solve this?
There repository can be found here.