在Rasperry Pi Jesse上运行的Kivy应用程序上没有音频输出

时间:2017-01-11 22:59:24

标签: raspberry-pi kivy raspbian raspberry-pi3 kivy-language

尊敬的同事 -

我希望你做得好。我希望你能帮我弄清楚在Raspberry Pi上运行Kivy的奇怪音频问题。简而言之,我无法让Kivy在Raspberry Pi上运行任何音频。我不确定其他硬件,因为我只在RPi上开发。我的代码如下。这只是一个简单的音板应用程序。按一个按钮,它会播放一个文件。它应该在理论上起作用,但它并没有。我已阅读每一篇相关的StackOverflow和Reddit帖子。我已尝试过几十种代码变体。无论我做什么,Kivy仍然像老鼠一样沉默。

以下是我正在运行的内容:

  • Raspberry Pi 3 Model B
  • Rasbian - Linux raspberrypi 4.4.38-v7 +#938 SMP Thu Dec 15 15:22:21 GMT 2016 armv7l GNU / Linux
  • Kivy - 1.9.2-dev0

我尝试过的事情:

  • USB Audio&系统音频 - 我尝试使用系统音频(耳机)插孔和USB声卡。具体来说,我使用的是可插拔USB耳机适配器。是的,我的扬声器已插入正确的端口。我已将配置文件更新为默认的USB适配器,因为我从系统板输出受到太多干扰。

  • 格式 - 我已尝试过MP3,WAV,OGG格式。没有骰子。 从终端播放 - 我可以使用其他方法让系统产生音频。我可以使用mpg321让Rasbian播放音频和终端。这个命令" mpg321" /home/pi/burnedpi/assets/audio/scotch.mp3"将成功解码并播放MP3文件。

  • 通过USB输出声音很好。我已经在终端上使用" speaker-test -c2 -t wav"测试了我的扬声器。命令他们工作。

  • 我已经在alsmixer中调整并确认了我的音频内部音频混音器设置。声卡已正确调高音量。

  • 其他命令和程序工作 - 我很确定这个问题与Pi上的Kivy有关。其他应用程序能够产生完美的声音。 示例

  • Kivy音频应用程序无法正常工作 - 默认情况下安装的官方Kivy音频示例不会产生任何音频。

基本上,我只想让Kivy输出声音。我有一个真正的简单脚本,在单击鼠标时输出音频文件。

我真的卡住了,不知道接下来该做什么。任何帮助将不胜感激。

干杯。

史蒂夫。

这是我的代码。

我的间距/标签是正确的,但是格式化很难格式化

* main.py *

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ListProperty, ObjectProperty, NumericProperty
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.audio import SoundLoader


class SoundBoard(Screen):
    def scotch(self):
    sound = SoundLoader.load('../assets/audio/scotch.wav')
    if sound:
        sound.play()
        sound.seek(0.00)
        print("Sound found at %s" % sound.source)
        print("Sound is %.3f seconds" % sound.length)
        print("Sound status %s" % sound.status)

class RootScreen(ScreenManager):
    pass

class audio(App):
    def build(self):
        return SoundBoard()

if __name__ == "__main__":
    audio().run()

audio.kv

<RootScreen>
    SoundBoard:

<SoundBoard>
    name: 'soundboard'
    BoxLayout:
        Button:
            text:   'i love scotch scotchy scotch scotch'
            on_press:   root.scotch()

*以下是我运行代码时得到的结果:*

pi@raspberrypi:~ $ python burnedpi/audio/main.py
[INFO   ] [Logger      ] Record log in /home/pi/.kivy/logs/kivy_17-01-11_84.txt
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] [Kivy        ] v1.9.2-dev0
[INFO   ] [Python      ] v2.7.9 (default, Sep 17 2016, 20:26:04)
[GCC 4.9.2]
[INFO   ] [Factory     ] 193 symbols loaded
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [AudioGstplayer] Using Gstreamer 1.4.4.0
[INFO   ] [Audio       ] Providers: audio_gstplayer, audio_sdl2 (audio_ffpyplayer ignored)
[INFO   ] [Window      ] Provider: egl_rpi
[INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
[INFO   ] [GL          ] Backend used <gl>
[INFO   ] [GL          ] OpenGL version <OpenGL ES 2.0>
[INFO   ] [GL          ] OpenGL vendor <Broadcom>
[INFO   ] [GL          ] OpenGL renderer <VideoCore IV HW>
[INFO   ] [GL          ] OpenGL parsed version: 2, 0
[INFO   ] [GL          ] Shading version <OpenGL ES GLSL ES 1.00>
[INFO   ] [GL          ] Texture max size <2048>
[INFO   ] [GL          ] Texture max units <8>
[INFO   ] [Shader      ] fragment shader: <Compiled>
[INFO   ] [Shader      ] vertex shader: <Compiled>
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [OSC         ] using <multiprocessing> for socket
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event0
[INFO   ] [MTD         ] Read event from </dev/input/event0>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event1
[INFO   ] [MTD         ] Read event from </dev/input/event1>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event0
[INFO   ] [HIDInput    ] Read event from </dev/input/event0>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event1
[INFO   ] [HIDInput    ] Read event from </dev/input/event1>
[INFO   ] [Base        ] Start application main loop
[INFO   ] [MTD         ] </dev/input/event0> range position X is 0 - 800
[INFO   ] [MTD         ] </dev/input/event0> range position Y is 0 - 480
[INFO   ] [MTD         ] </dev/input/event0> range touch major is 0 - 0
[INFO   ] [MTD         ] </dev/input/event0> range touch minor is 0 - 0
[INFO   ] [MTD         ] </dev/input/event0> range pressure is 0 - 255
[INFO   ] [MTD         ] </dev/input/event0> axes invertion: X is 0, Y is 0
[INFO   ] [MTD         ] </dev/input/event0> rotation set to 0
[INFO   ] [MTD         ] </dev/input/event1> range position X is 0 - 0
[INFO   ] [MTD         ] </dev/input/event1> range position Y is 0 - 0
[INFO   ] [HIDMotionEvent] using <FT5406 memory based driver>
[INFO   ] [MTD         ] </dev/input/event1> range touch major is 0 - 0
[INFO   ] [HIDMotionEvent] <FT5406 memory based driver> range ABS X position is 0 - 800
[INFO   ] [MTD         ] </dev/input/event1> range touch minor is 0 - 0
[INFO   ] [HIDMotionEvent] <FT5406 memory based driver> range ABS Y position is 0 - 480
[INFO   ] [MTD         ] </dev/input/event1> range pressure is 0 - 255
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [HIDMotionEvent] <FT5406 memory based driver> range position X is 0 - 800
[INFO   ] [MTD         ] </dev/input/event1> axes invertion: X is 0, Y is 0
[INFO   ] [HIDMotionEvent] <FT5406 memory based driver> range position Y is 0 - 480
[INFO   ] [HIDMotionEvent] using <C-Media Electronics Inc. USB Audio Device>
[INFO   ] [MTD         ] </dev/input/event1> rotation set to 0
Sound found at /home/pi/burnedpi/assets/audio/scotch.wav
Sound is 5.486 seconds
Sound status play

以下是Kivy日志文件中的信息

[INFO   ] Logger: Record log in /home/pi/.kivy/logs/kivy_17-01-11_84.txt
[INFO   ] Image: Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] Kivy: v1.9.2-dev0
[INFO   ] Python: v2.7.9 (default, Sep 17 2016, 20:26:04) 
[GCC 4.9.2]
[INFO   ] Factory: 193 symbols loaded
[INFO   ] Text: Provider: sdl2
[INFO   ] AudioGstplayer: Using Gstreamer 1.4.4.0
[INFO   ] Audio: Providers: audio_gstplayer, audio_sdl2 (audio_ffpyplayer ignored)
[INFO   ] Window: Provider: egl_rpi
[INFO   ] GL: Using the "OpenGL ES 2" graphics system
[INFO   ] GL: Backend used <gl>
[INFO   ] GL: OpenGL version <OpenGL ES 2.0>
[INFO   ] GL: OpenGL vendor <Broadcom>
[INFO   ] GL: OpenGL renderer <VideoCore IV HW>
[INFO   ] GL: OpenGL parsed version: 2, 0
[INFO   ] GL: Shading version <OpenGL ES GLSL ES 1.00>
[INFO   ] GL: Texture max size <2048>
[INFO   ] GL: Texture max units <8>
[INFO   ] Shader: fragment shader: <Compiled>
[INFO   ] Shader: vertex shader: <Compiled>
[INFO   ] Window: virtual keyboard not allowed, single mode, not docked
[INFO   ] OSC: using <multiprocessing> for socket
[INFO   ] ProbeSysfs: device match: /dev/input/event0
[INFO   ] MTD: Read event from </dev/input/event0>
[INFO   ] ProbeSysfs: device match: /dev/input/event1
[INFO   ] MTD: Read event from </dev/input/event1>
[INFO   ] ProbeSysfs: device match: /dev/input/event0
[INFO   ] HIDInput: Read event from </dev/input/event0>
[INFO   ] ProbeSysfs: device match: /dev/input/event1
[INFO   ] HIDInput: Read event from </dev/input/event1>
[INFO   ] Base: Start application main loop
[INFO   ] MTD: </dev/input/event0> range position X is 0 - 800
[INFO   ] MTD: </dev/input/event0> range position Y is 0 - 480
[INFO   ] MTD: </dev/input/event0> range touch major is 0 - 0
[INFO   ] MTD: </dev/input/event0> range touch minor is 0 - 0
[INFO   ] MTD: </dev/input/event0> range pressure is 0 - 255
[INFO   ] MTD: </dev/input/event0> axes invertion: X is 0, Y is 0
[INFO   ] MTD: </dev/input/event0> rotation set to 0
[INFO   ] MTD: </dev/input/event1> range position X is 0 - 0
[INFO   ] MTD: </dev/input/event1> range position Y is 0 - 0
[INFO   ] HIDMotionEvent: using <FT5406 memory based driver>
[INFO   ] MTD: </dev/input/event1> range touch major is 0 - 0
[INFO   ] HIDMotionEvent: <FT5406 memory based driver> range ABS X position is 0 - 800
[INFO   ] MTD: </dev/input/event1> range touch minor is 0 - 0
[INFO   ] HIDMotionEvent: <FT5406 memory based driver> range ABS Y position is 0 - 480
[INFO   ] MTD: </dev/input/event1> range pressure is 0 - 255
[INFO   ] GL: NPOT texture support is available
[INFO   ] HIDMotionEvent: <FT5406 memory based driver> range position X is 0 - 800
[INFO   ] MTD: </dev/input/event1> axes invertion: X is 0, Y is 0
[INFO   ] HIDMotionEvent: <FT5406 memory based driver> range position Y is 0 - 480
[INFO   ] HIDMotionEvent: using <C-Media Electronics Inc. USB Audio Device>
[INFO   ] MTD: </dev/input/event1> rotation set to 0
[INFO   ] Base: Leaving application in progress...
[WARNING] stderr: Traceback (most recent call last):
[WARNING] stderr:   File "burnedpi/audio/main.py", line 27, in <module>
[WARNING] stderr:     audio().run()
[WARNING] stderr:   File "/usr/local/lib/python2.7/dist-packages/kivy/app.py", line 828, in run
[WARNING] stderr:     runTouchApp()
[WARNING] stderr:   File "/usr/local/lib/python2.7/dist-packages/kivy/base.py", line 504, in runTouchApp
[WARNING] stderr:     EventLoop.window.mainloop()
[WARNING] stderr:   File "/usr/local/lib/python2.7/dist-packages/kivy/core/window/window_egl_rpi.py", line 90, in mainloop
[WARNING] stderr:     self._mainloop()
[WARNING] stderr:   File "/usr/local/lib/python2.7/dist-packages/kivy/core/window/window_egl_rpi.py", line 85, in _mainloop
[WARNING] stderr:     EventLoop.idle()
[WARNING] stderr:   File "/usr/local/lib/python2.7/dist-packages/kivy/base.py", line 339, in idle
[WARNING] stderr:     Clock.tick()
[WARNING] stderr:   File "/usr/local/lib/python2.7/dist-packages/kivy/clock.py", line 553, in tick
[WARNING] stderr:     current = self.idle()
[WARNING] stderr:   File "/usr/local/lib/python2.7/dist-packages/kivy/clock.py", line 533, in idle
[WARNING] stderr:     usleep(1000000 * sleeptime)
[WARNING] stderr:   File "/usr/local/lib/python2.7/dist-packages/kivy/clock.py", line 717, in usleep
[WARNING] stderr:     _usleep(microseconds, self._sleep_obj)
[WARNING] stderr:   File "/usr/local/lib/python2.7/dist-packages/kivy/clock.py", line 445, in _usleep
[WARNING] stderr:     _libc_usleep(int(microseconds))
[WARNING] stderr: KeyboardInterrupt

1 个答案:

答案 0 :(得分:1)

想出来。在导入Kivy之前设置环境变量。将其添加到文件的顶部。

import os
os.environ['KIVY_AUDIO'] = 'sdl2'

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ListProperty, ObjectProperty, NumericProperty
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.audio import SoundLoader

class SoundBoard(Screen):
    def scotch(self):
        sound = SoundLoader.load('../assets/audio/scotch.wav')
        if sound:
            sound.play()
            sound.seek(0.00)
            print("Sound found at %s" % sound.source)
            print("Sound is %.3f seconds" % sound.length)
            print("Sound status %s" % sound.status)

class RootScreen(ScreenManager):
    pass

class audio(App):
    def build(self):
        return SoundBoard()

if __name__ == "__main__":
    audio().run()

确保在导入Kivy之前设置环境变量。使用以下格式:

import os
os.environ['KIVY_AUDIO'] = 'sdl2'

查看https://kivy.org/docs/guide/environment.html了解详情。