首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Alsa作为root运行

Alsa作为root运行
EN

Stack Overflow用户
提问于 2022-01-27 04:19:35
回答 1查看 391关注 0票数 1

我试图在raspberry pi上在python代码中播放一个声音文件。Unfortuantley一些库,我正在使用(罗孚工具包)需要运行作为根。当我尝试播放音频文件时,我会得到下面的错误。很明显,这个问题是以root的形式运行的,但不幸的是,我的另一个库要求我作为root运行。

有什么方法可以从根用户那里播放音频吗?

谢谢。

下面是我的python代码:

代码语言:javascript
复制
from pydub import AudioSegment
from pydub.playback import play

import os

class JohnnyAudio():

    def __init__(self):
        self.missle = AudioSegment.from_wav("Code/Server/mw2missillaunch.wav")

    def playMissle(self):
        play(self.missle)

以及控制台输出:

代码语言:javascript
复制
XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e g happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e g happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
Input #0, wav, from '/tmp/tmpfu0s_02d.wav':   0KB sq=    0B f=0/0   
  Duration: 00:00:02.34, bitrate: 176 kb/s
    Stream #0:0: Audio: pcm_u8 ([1][0][0][0] / 0x0001), 22050 Hz, 1 channels, u8, 176 kb/s
XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e g happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM default
SDL_OpenAudio (1 channels, 22050 Hz): ALSA: Couldn't open audio device: No such file or directory
No more combinations to try, audio open failed
Failed to open file '/tmp/tmpfu0s_02d.wav' or configure filtergraph
    nan    :  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0   

        Stream #0:0: Audio: pcm_u8 ([1][0][0][0] / 0x0001), 22050 Hz, 1 channels, u8, 176 kb/s
    XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e g happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM default

试图运行的文件的权限:

代码语言:javascript
复制
-rw-r--r-- 1 pi pi 51708 Aug 23  2012 mw2missillaunch.wav
EN

回答 1

Stack Overflow用户

发布于 2022-09-28 16:31:59

有,但我只能在pi3上做一次。

它基于以下代码:https://github.com/shivasiddharth/PulseAudio-System-Wide

不管怎么说,这对我来说似乎不再适用了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70873303

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档