我试图在raspberry pi上在python代码中播放一个声音文件。Unfortuantley一些库,我正在使用(罗孚工具包)需要运行作为根。当我尝试播放音频文件时,我会得到下面的错误。很明显,这个问题是以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)以及控制台输出:
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发布于 2022-09-28 16:31:59
https://stackoverflow.com/questions/70873303
复制相似问题