pythonspeech-recognitionspeech-to-textgoogle-speech-api

show_all = False not working with SpeechRecognition 3.9


I'm using the following code to transcribe audio files using this package version 3.9.x, which worked with no issues a year ago. While it produces the desired output, it keeps printing the whole process (all the iterations of transcriptions and their accuracy) even though I have explicitly set show_all = False. The output I get is normal, I merely want to stop it from printing the whole process while running. Has anyone else had this issue/found a workaround?

import speech_recognition as sr

r = sr.Recognizer()

with sr.AudioFile(filename) as source:
    audio_data = r.record(source)
    text = r.recognize_google(audio_data,language='ru-RU', show_all=False)
    

Solution

  • No issue on my side with SpeechRecognition 3.10.0.

    Issue seems present in 3.9.0, and related to [this pull ticket #651]https://github.com/Uberi/speech_recognition/pull/651) related to this issue #645, quoting:

    When calling recognize_google method of speech_recognition it prints the entire JSON response, investigating the problem is on the 917 and 918 lines of speech_recognition_init_.py

    with 3.9.0

    pip install SpeechRecognition==3.9.0 --force-reinstall
    
    ipython
    
    In [1]: import speech_recognition as sr
       ...:
       ...: r = sr.Recognizer()
       ...: # source: https://www.liveatc.net/recordings.php line:
       ...: # 2023-03-03 10:34:20   Balloon warning KPBI (humorous)     kb4tez 
       ...: # https://forums.liveatc.net/index.php?action=dlattach;topic=16994.0;attach=11640
       ...: filename = r"balloonKPBI2-Twr-Mar-02-2023-2100Z.mp3_converted.wav"
       ...: with sr.AudioFile(filename) as source:
       ...:     audio_data = r.record(source)
       ...:     text = r.recognize_google(audio_data,language='en-EN', show_all=False)
       ...:
    result2:
    {   'alternative': [   {   'confidence': 0.9437989,
                               'transcript': 'clear land 10 left frontier by 26 '
                                             '790 times there was a balloon at '
                                             '1200 feet on the final few and '
                                             'frontier sorry Roger Customs Eddie '
                                             'one custom jet 960 3 is with young '
                                             'visual get 963 Tower and my 101 left '
                                             'continue travel be holding a '
                                             'position used caution balloons '
                                             'reported on spinal 1200 feet so '
                                             'great the Chinese variety again all '
                                             'right 963'},
                           {   'transcript': 'clear land 10 left frontier by 26 '
                                             '790 times there was a balloon at '
                                             '1200 feet on the final few and '
                                             'frontier sorry Roger Customs Eddie '
                                             'one custom jet 960 3 is with young '
                                             'visual get 963 Tower and my 101 left '
                                             'continue travel be holding a '
                                             'position used caution balloons '
                                             'reported on spinal 1200 feet so '
                                             'great the Chinese variety again '
                                             'alright 963'},
                           {   'transcript': 'clear land 10 left frontier by 26 '
                                             '790 times there was a balloon at '
                                             '1200 feet on the final few and '
                                             'frontier sorry custom said he won '
                                             'custom jet 960 3 is with young '
                                             'visual get 963 Tower and my 101 left '
                                             'continue travel be holding a '
                                             'position used caution balloons '
                                             'reported on spinal 1200 feet so '
                                             'great the Chinese variety again all '
                                             'right 963'},
                           {   'transcript': 'clear land 10 left frontier by 26 '
                                             '790 times there was a balloon at '
                                             '1200 feet on the final few and '
                                             'frontier sorry Roger Customs Eddy '
                                             'one custom jet 960 3 is with young '
                                             'visual get 963 Tower and my 101 left '
                                             'continue travel be holding a '
                                             'position used caution balloons '
                                             'reported on spinal 1200 feet so '
                                             'great the Chinese variety again all '
                                             'right 963'},
                           {   'transcript': 'clear land 10 left frontier by 26 '
                                             '790 times there was a balloon at '
                                             '1200 feet on the final few and '
                                             'frontier sorry Roger Customs Eddie '
                                             'one custom jet 960 3 is with young '
                                             'visual get 963 Tower and my 101 left '
                                             'continue travel be holding a '
                                             'position used caution balloons '
                                             'reported on spinal 1,200 feet so '
                                             'great the Chinese variety again all '
                                             'right 963'}],
        'final': True}
    
    In [2]: sr.__version__
    Out[2]: '3.9.0'
    In [3]: import sys
    
    In [4]: sys.version
    Out[4]: '3.10.7 (tags/v3.10.7:6cc6b13, Sep  5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)]'
    

    with 3.10.0

    pip install SpeechRecognition==3.9.0 --force-reinstall
    
    ipython
    
    In [1]: import speech_recognition as sr
       ...:
       ...: r = sr.Recognizer()
       ...: # source: https://www.liveatc.net/recordings.php line:
       ...: # 2023-03-03 10:34:20   Balloon warning KPBI (humorous)     kb4tez 
       ...: # https://forums.liveatc.net/index.php?action=dlattach;topic=16994.0;attach=11640
       ...: filename = r"balloonKPBI2-Twr-Mar-02-2023-2100Z.mp3_converted.wav"
       ...: with sr.AudioFile(filename) as source:
       ...:     audio_data = r.record(source)
       ...:     text = r.recognize_google(audio_data,language='en-EN', show_all=False)
       ...:
    
    In [2]: text
    Out[2]: 'clear land 10 left frontier by 26 790 times there was a balloon at 1200 feet on the final few and frontier sorry Roger Customs Eddie one custom jet 960 3 is with young visual get 963 Tower and my 101 left continue travel be holding a position used caution balloons reported on spinal 1200 feet so great the Chinese variety again all right 963'
    
    In [3]: len(text)
    Out[3]: 342
    
    In [4]: sr.__version__
    Out[4]: '3.10.0'
    
    In [5]: import sys
    
    In [6]: sys.version
    Out[6]: '3.10.7 (tags/v3.10.7:6cc6b13, Sep  5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)]'