0

Im a newbie in python and im trying to do an app convert wav file but i dont know why my code cant run and it report this My code:

import speech_recognition as sr

r = sr.Recognizer()
with sr.AudioFile('idk.wav') as source:
  audio = r.record(source)
try:
 s = r.recognize_google(audio)
 print(s)
except:
 print("try again")

Report

Traceback (most recent call last):
File "D:\Trans wav to text\venv\lib\site-packages\speech_recognition\__init__.py", line 203, in __enter__
self.audio_reader = wave.open(self.filename_or_fileobject, "rb")
File "D:\Python\lib\wave.py", line 510, in open
return Wave_read(f)
File "D:\Python\lib\wave.py", line 164, in __init__
self.initfp(f)
File "D:\Python\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 "D:\Trans wav to text\venv\lib\site-packages\speech_recognition\__init__.py", line 208, in __enter__
self.audio_reader = aifc.open(self.filename_or_fileobject, "rb")
File "D:\Python\lib\aifc.py", line 917, in open
return Aifc_read(f)
File "D:\Python\lib\aifc.py", line 352, in __init__
self.initfp(file_object)
File "D:\Python\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 "D:\Trans wav to text\venv\lib\site-packages\speech_recognition\__init__.py", line 234, in __enter__
self.audio_reader = aifc.open(aiff_file, "rb")
File "D:\Python\lib\aifc.py", line 917, in open
return Aifc_read(f)
File "D:\Python\lib\aifc.py", line 358, in __init__
self.initfp(f)
File "D:\Python\lib\aifc.py", line 314, in initfp
chunk = Chunk(file)
File "D:\Python\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 "D:/Trans wav to text/main.py", line 4, in <module>
with sr.AudioFile('idk.wav') as source:
File "D:\Trans wav to text\venv\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

Can someone help me please, i searched this on google but it's not work :( ignore this :ygwydgwdfgwtfgdyuwhdiugwtfduiwjdiugwyudhwhdfywfyuwwwwwwyuagdujwabdyufsayudbajwndyfavyufbwaudbwygdfyabwfuwagfyvawdfaw

  • look this: https://pypi.org/project/google-cloud-speech/ – Jasar Orion Nov 10 '20 at 11:42
  • I think it is complaining it is not a proper .wav file, and it can't find the RIFF id at the start of the file. Perhaps you could try with another wav file? – ocrdu Nov 10 '20 at 11:47
  • ah yes i tried with another wav file and it still not working – trimai_ Nov 10 '20 at 12:05
  • does this answer your question? https://stackoverflow.com/questions/25672289/failed-to-open-file-file-wav-as-a-wav-due-to-file-does-not-start-with-riff-id – PApostol Nov 10 '20 at 12:15

0 Answers0