簡體   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