Skip to content
Related Articles

Related Articles

Improve Article

Python – Add audio files in kivy

  • Last Updated : 23 Jan, 2020

Kivy is a platform independent GUI tool in Python. Kivy is a tool used to build cross-platform applications in Python which can run on android, IOS, Linux, Windows.

Audio Widget:
This module is used to load audio files in kivy.

 from import SoundLoader 

Below is the code on how you can import an audio file in kivy.

NOTE:You can import audio files with only ‘.wav’ format.

from import App
from kivy.uix.boxlayout import BoxLayout
from import SoundLoader
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
class Tester(BoxLayout):
    def __init__(self, **kwargs):
    def play_sound(self):
        sound = SoundLoader.load('sampleaudio.wav')
        if sound:
class SampleApp(App):
    def build(self):
        return Tester()
myApp = SampleApp()

.kv file of the above code [Sample.kv]:

    orientation: "vertical"
    spacing: 50
    space_x: self.size[0]/3
            rgba: (0, 0, 0, 0)
            size: self.size
            pos: self.pos
            size_hint:0.6, 0.1
            pos_hint :{'center_x':0.5, 'center_y':0.3}
            background_color: (1, .36, .4, .55)
            on_release: root.play_sound()


The output of the following code will be as shown below which will play an audio file ‘sampleaudio.wav’ when we click the play button.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :