繁体   English   中英

Alsa 以 root 身份运行

[英]Alsa to run as root

我正在尝试在树莓派上的 python 代码中播放声音文件。 不幸的是,我正在使用的一些库(流动站工具包)需要以根用户身份运行。 当我尝试播放音频文件时,出现以下错误。 很明显,问题是以 root 身份运行,但不幸的是,我的其他库之一要求我以 root 身份运行。

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

谢谢你。

这是我的 python 代码:

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)

和控制台 output:

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

尝试运行文件的权限:

-rw-r--r-- 1 pi pi 51708 Aug 23  2012 mw2missillaunch.wav

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

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

无论如何,这对我来说似乎不再有用了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM