<commit_before>"""High-level interface to a opus.api.encoder functions"""

from opus.api import encoder, ctl


class Encoder(object):

    def __init__(self, fs, channels, application):
        """
        Parameters:
            fs : sampling rate
            channels : number of channels
        """

        self._fs = fs
        self._channels = channels
        self._application = application
        self._state = encoder.create(fs, channels, application)

    def __del__(self):
        if hasattr(self, '_state'):
            # Destroying state only if __init__ completed successfully
            encoder.destroy(self._state)

    def reset_state(self):
        """Resets the codec state to be equivalent to a freshly initialized state"""

        encoder.ctl(self._state, ctl.reset_state)<commit_msg>'application' parameter of the opus.Encoder can be a string like a 'voip' or 'audio'<commit_after>"""High-level interface to a opus.api.encoder functions"""

from opus.api import encoder, ctl, constants

APPLICATION_TYPES_MAP = {
    'voip': constants.APPLICATION_VOIP,
    'audio': constants.APPLICATION_AUDIO,
    'restricted_lowdelay': constants.APPLICATION_RESTRICTED_LOWDELAY,
}


class Encoder(object):

    def __init__(self, fs, channels, application):
        """
        Parameters:
            fs : sampling rate
            channels : number of channels
        """

        if application in APPLICATION_TYPES_MAP.keys():
            application = APPLICATION_TYPES_MAP[application]
        elif application in APPLICATION_TYPES_MAP.values():
            pass  # Nothing to do here
        else:
            raise ValueError("`application` value must be in 'voip', 'audio' or 'restricted_lowdelay'")

        self._fs = fs
        self._channels = channels
        self._application = application
        self._state = encoder.create(fs, channels, application)

    def __del__(self):
        if hasattr(self, '_state'):
            # Destroying state only if __init__ completed successfully
            encoder.destroy(self._state)

    def reset_state(self):
        """Resets the codec state to be equivalent to a freshly initialized state"""

        encoder.ctl(self._state, ctl.reset_state)
{'fraction_non_alphanumeric': 0.09009009009009009, 'fraction_numerical': 0.0, 'mean_word_length': 2.6771523178807946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6765285', 'n_tokens_mistral': 613, 'n_tokens_neox': 580, 'n_words': 176}