<commit_before>import speech_recognition as sr

from .utils import BaseParser


class Parser(BaseParser):
    """
    Extract text (i.e. speech) from an audio file, using SpeechRecognition.
    Only works with .wav files, for now.
    """

    def extract(self, filename, **kwargs):
        r = sr.Recognizer()

        with sr.WavFile(filename) as source:
            audio = r.record(source)

        try:
            speech = r.recognize(audio)
        except LookupError:  # audio is not understandable
            speech = ''

        return speech<commit_msg>added testing info to docstring for future reference<commit_after>import speech_recognition as sr

from .utils import BaseParser


class Parser(BaseParser):
    """
    Extract text (i.e. speech) from an audio file, using SpeechRecognition.
    Only works with .wav files, for now.
    Note: for testing, use -
    http://www2.research.att.com/~ttsweb/tts/demo.php,
    with Rich (US English) for best results
    """

    def extract(self, filename, **kwargs):
        r = sr.Recognizer()

        with sr.WavFile(filename) as source:
            audio = r.record(source)

        try:
            speech = r.recognize(audio)
        except LookupError:  # audio is not understandable
            speech = ''

        return speech
{'fraction_non_alphanumeric': 0.09175019275250579, 'fraction_numerical': 0.0007710100231303007, 'mean_word_length': 2.354005167958656, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '2338679', 'n_tokens_mistral': 389, 'n_tokens_neox': 362, 'n_words': 120}