Steve Yoss
Steve Yoss

Reputation: 13

No Audio Output on Kivy Applications Running on a Rasperry Pi Jesse

Esteemed Colleagues --

I hope you're doing well. I'm hoping you can help me figure out a weird audio issue running Kivy on Raspberry Pi. In a nutshell, I can't get Kivy to produce any audio running on Raspberry Pi. I'm not sure on other hardware as I'm only developing on RPi. My code is below. This is just a simple soundboard app. Press a button and it plays a file. It should work in theory, but it doesn't. I have read every single relevant StackOverflow and Reddit post. I've tried dozens of variations of my code. No matter what I do Kivy is still as silent as mouse.

Here is what I'm running:

What I've tried:

Essentially, I'm just trying to get Kivy to output sound. I've got a real simple script that outputs an audio file when a mouse is clicked.

I'm really stuck and don't know what to do next. Any help would be greatly appreciated.

Cheers.

Steve.

Here is my code.

My spacing/tabs are correct, but Stack makes it hard to format

* 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()

* Here is what I get when I run the code: *

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

Here is the information from the Kivy Log File

[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

Upvotes: 0

Views: 1045

Answers (1)

Steve Yoss
Steve Yoss

Reputation: 13

Figured it out. Set the enviromental variable prior to importing Kivy. Add this to the top of the file.

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()

Make sure you set your environmental variables prior to importing Kivy. Use this format:

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

Check out https://kivy.org/docs/guide/environment.html for more information.

Upvotes: 1

Related Questions