-1
import speech_recognition as sr
print(sr.__version__)
r = sr.Recognizer()

file_audio = sr.AudioFile('damn1.mp3')

with file_audio as source:
   audio_text = r.record(source)

print(type(audio_text))
print(r.recognize_google(audio_text))

I have a problem running this program. The output I get is as following:

Traceback (most recent call last):
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 203, in __enter__
    self.audio_reader = wave.open(self.filename_or_fileobject, "rb")
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\wave.py", line 510, in open
    return Wave_read(f)
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\wave.py", line 164, in __init__
    self.initfp(f)
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\wave.py", line 131, in initfp
    raise Error('file does not start with RIFF id')
wave.Error: file does not start with RIFF id

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 208, in __enter__
    self.audio_reader = aifc.open(self.filename_or_fileobject, "rb")
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 917, in open
    return Aifc_read(f)
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 352, in __init__
    self.initfp(file_object)
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 316, in initfp
    raise Error('file does not start with FORM id')
aifc.Error: file does not start with FORM id

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 234, in __enter__
    self.audio_reader = aifc.open(aiff_file, "rb")
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 917, in open
    return Aifc_read(f)
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 358, in __init__
    self.initfp(f)
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 314, in initfp
    chunk = Chunk(file)
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\chunk.py", line 63, in __init__
    raise EOFError
EOFError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\kubar\OneDrive\Pulpit\men.py", line 7, in <module>
    with file_audio as source:
  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 236, in __enter__
    raise ValueError("Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format")
ValueError: Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format
susenj
  • 342
  • 1
  • 4
  • 12
Kuba
  • 5
  • 6
  • try using pygame.mixer or pygame.music see [docs](https://www.pygame.org/docs/ref/music.html) – Matiiss Oct 28 '20 at 08:55
  • Also [check the docs](https://github.com/Uberi/speech_recognition/blob/master/reference/library-reference.rst#audiofilefilename_or_fileobject-unionstr-ioiobase---audiofile) about supported fie formats – buran Oct 28 '20 at 09:02

1 Answers1

1

MP3 is a compressed format. Never use it when you manipulate audio since the large majority of tools handling audio does it on non compressed audio streams. So, even when such tool accepts your file, it probably starts by converting it, which consumes time and spaces. Moreover, MP3 is never used by professionals working on audio (musician, engineers, etc.) : avoid using it with audio materials having some importance for your work (even for archiving because the compression is not reversible), always prefer using non compressed formats as WAV or AIF instead (here the library seems to expect AIF).

dspr
  • 2,383
  • 2
  • 15
  • 19