<commit_before>'''
Audio
=====

Core class for loading and play sound.

.. note::

    Recording audio is not supported.

'''

__all__ = ('Sound', 'SoundLoader')

import sys
from kivy.logger import Logger
from kivy.event import EventDispatcher
from kivy.core import core_register_libs


class SoundLoader:
    '''Load a sound, with usage of the best loader for a given filename.
    If you want to load an audio file ::

        sound = SoundLoader.load(filename='test.wav')
        if not sound:
            # unable to load this sound ?
            pass
        else:
            # sound loaded, let's play!
            sound.play()

    '''

    _classes = []

    @staticmethod
    def register(classobj):
        '''Register a new class to load sound'''
        Logger.debug('Audio: register %s' % classobj.__name__)
        SoundLoader._classes.append(classobj)

    @staticmethod
    def load(filename):
        '''Load a sound, and return a Sound() instance'''
        ext = filename.split('.')[-1].lower()
        for classobj in SoundLoader._classes:
            if ext in classobj.extensions():
                return classobj(filename=filename)
        Logger.warning('Audio: Unable to found a loader for <%s>' %
                       filename)
        return None


class Sound(EventDispatcher):
    '''Represent a sound to play. This class is abstract, and cannot be used
    directly.
    Use SoundLoader to load a sound !

    :Events:
        `on_play` : None
            Fired when the sound is played
        `on_stop` : None
            Fired when the sound is stopped
    '''

    __slots__ = ('_filename', '_volume', '_status')

    def __init__(self, **kwargs):
        kwargs.setdefault('filename', None)
        kwargs.setdefault('volume', 1.)

        super(Sound, self).__init__(**kwargs)

        self.register_event_type('on_play')
        self.register_event_type('on_stop')

        self._status = 'stop'<commit_msg>sound: fix audio class creation<commit_after>'''
Audio
=====

Core class for loading and play sound.

.. note::

    Recording audio is not supported.

'''

__all__ = ('Sound', 'SoundLoader')

import sys
from kivy.logger import Logger
from kivy.event import EventDispatcher
from kivy.core import core_register_libs


class SoundLoader:
    '''Load a sound, with usage of the best loader for a given filename.
    If you want to load an audio file ::

        sound = SoundLoader.load(filename='test.wav')
        if not sound:
            # unable to load this sound ?
            pass
        else:
            # sound loaded, let's play!
            sound.play()

    '''

    _classes = []

    @staticmethod
    def register(classobj):
        '''Register a new class to load sound'''
        Logger.debug('Audio: register %s' % classobj.__name__)
        SoundLoader._classes.append(classobj)

    @staticmethod
    def load(filename):
        '''Load a sound, and return a Sound() instance'''
        ext = filename.split('.')[-1].lower()
        for classobj in SoundLoader._classes:
            if ext in classobj.extensions():
                return classobj(filename=filename)
        Logger.warning('Audio: Unable to found a loader for <%s>' %
                       filename)
        return None


class Sound(EventDispatcher):
    '''Represent a sound to play. This class is abstract, and cannot be used
    directly.
    Use SoundLoader to load a sound !

    :Events:
        `on_play` : None
            Fired when the sound is played
        `on_stop` : None
            Fired when the sound is stopped
    '''

    __slots__ = ('_filename', '_volume', '_status')

    def __init__(self, **kwargs):
        kwargs.setdefault('filename', None)
        kwargs.setdefault('volume', 1.)

        super(Sound, self).__init__()

        self.register_event_type('on_play')
        self.register_event_type('on_stop')

        self._status = 'stop'
{'fraction_non_alphanumeric': 0.10471070148489503, 'fraction_numerical': 0.0010240655401945725, 'mean_word_length': 2.3026204564666104, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6510432', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1055, 'n_words': 361}