I am transcoding some audio files using the speech recognition package in Python, and I am getting a KeyError (io.BufferedReader) when I am recording the file. I am not really sure what it means or how to solve it. Any help would be appreciated.
Below are my code and error.
import speech_recognition as sr
r = sr.Recognizer()
AudioFile = sr.AudioFile('/Users/USERNAME/Audio_file.wav')
with AudioFile as source:
audio = r.record(source)
Expected results:
string variable with the audio transcript.
Actual results: The following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 2, in <module>
File "/Users/USERNAME/anaconda2/envs/python_sr/lib/python3.7/site-packages/speech_recognition/__init__.py",line 295, in __exit__ self.audio_reader.close()
File "/Users/USERNAME/anaconda2/envs/python_sr/lib/python3.7/wave.py", line 194, in close file.close() File "<string>", line 131, in close
KeyError: <_io.BufferedReader name='/Users/USERNAME/Audio_file.wav'>
Related
I am trying to load sound files on a python script.
I installed, loaded the right version of modules, imported successfully librosa and soundfile, and even ffmpeg (which I found was a solution to this same error for mp3 files)
import os
import json
from scipy import signal
import librosa
[...]
y, sr = librosa.load(directory_path + filename + '.webm', mono = True)
My code works on notebooks (Kaggle) but somehow, and I can't figure out why, it doesn't work when uploaded on a computer cluster. And I really need the cluster for its computational power/memory. :/
The error:
Traceback (most recent call last):
File "/cluster/apps/nss/gcc-6.3.0/python/3.8.5/x86_64/lib64/python3.8/site-packages/librosa/core/audio.py", line 146, in load
with sf.SoundFile(path) as sf_desc:
File "/cluster/home/.local/lib/python3.8/site-packages/soundfile.py", line 740, in __init__
self._file = self._open(file, mode_int, closefd)
File "/cluster/home/.local/lib/python3.8/site-packages/soundfile.py", line 1264, in _open
_error_check(_snd.sf_error(file_ptr),
File "/cluster/home/.local/lib/python3.8/site-packages/soundfile.py", line 1455, in _error_check
raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening 'input/00092.webm': File contains data in an unknown format.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "analysis_python.py", line 47, in <module>
y,sr = librosa.load(directory_path + filename + '.webm')
File "/cluster/apps/nss/gcc-6.3.0/python/3.8.5/x86_64/lib64/python3.8/site-packages/librosa/core/audio.py", line 163, in load
y, sr_native = __audioread_load(path, offset, duration, dtype)
File "/cluster/apps/nss/gcc-6.3.0/python/3.8.5/x86_64/lib64/python3.8/site-packages/librosa/core/audio.py", line 187, in __audioread_load
with audioread.audio_open(path) as input_file:
File "/cluster/apps/nss/gcc-6.3.0/python/3.8.5/x86_64/lib64/python3.8/site-packages/audioread/__init__.py", line 116, in audio_open
raise NoBackendError()
audioread.exceptions.NoBackendError
I perused the internet for a solution but no luck. Thank you for your help in advance.
This is my code:
import speech_recognition as sr
r = sr.Recognizer()
file = sr.AudioFile('E:/music/jack.wav')
with file as source:
audio_file = r.record(source,duration=20)
print(r.recognize_google(source))
I am getting this error:
[Running] python -u "e:\Visual studio code\file-1.py"
Traceback (most recent call last):
File "e:\Visual studio code\file-1.py", line 8, in <module>
print(r.recognize_google(source))
File "C:\Users\asus\AppData\Roaming\Python\Python39\site-packages\speech_recognition\__init__.py", line 822, in recognize_google
assert isinstance(audio_data, AudioData), "``audio_data`` must be audio data"
AssertionError: ``audio_data`` must be audio data
How can I fix this?
instead of giving source to input of r.rcognize_google you should give audio_file for processing try it once!
import speech_recognition as sr
r = sr.Recognizer()
file = sr.AudioFile('E:/music/jack.wav')
with file as source:
audio_file = r.record(source,duration=20)
print(r.recognize_google(audio_file))
Exception in Tkinter callback:
Traceback (most recent call last):
File "/Users/choihyomin/anaconda3/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "/Users/choihyomin/Documents/GitHub/Doby_OS/main.py", line 9, in DobbyIsListening
dobby.dobyisfree()
File "/Users/choihyomin/Documents/GitHub/Doby_OS/dobby.py", line 15, in dobyisfree
audio = r.listen(source,timeout = 2)
File "/Users/choihyomin/anaconda3/lib/python3.7/site-packages/speech_recognition/__init__.py", line 618, in listen
raise WaitTimeoutError("listening timed out while waiting for phrase to start")
speech_recognition.WaitTimeoutError: listening timed out while waiting for phrase to start
Hi, I'm a student who studies python.
I'm making AI using SpeechRecognition module.
I saw a YouTube tutorial and coded.
I installed SpeechRecognition and PyAudio. But it is not working:
with sr.Microphone() as source:
print("도비는 듣고 있어요!")
audio = r.listen(source,timeout = 2)
This is the part where the error comes in my code.
Any help would be appreciated.
Thank you
So I tried to convert my midi file to ogg and I still cant get it to work... hope some of you can help me?
This is my code:
showTextScreen('Tetromino')
while True: # game loop
if random.randint(0, 1) == 0:
pygame.mixer.music.load('tetrisb.mid')
else:
pygame.mixer.music.load('tetrisc.mid')
pygame.mixer.music.play(-1, 0,0)
runGame()
pygame.mixer.music.stop()
showTextScreen('Game Over')
It gives the error that it cant open tetrisb.mid
I tried renaming it and it still says the same...
If i can fix this I can fix the other file probably
Here is the error:
Traceback (most recent call last):
File "H:\Programmering\Python\TETRIS!.py", line 487, in <module>
main()
File "H:\Programmering\Python\TETRIS!.py", line 166, in main
pygame.mixer.music.load('tetrisc.mid')
pygame.error: Couldn't open 'tetrisc.mid'
I'm using windows and python 3.8 and i dont mind if im using midi or ogg...
I changed my midi file into ogg, hoping it would fix the problem but it didnt.
My file is ogg atm
It looks like you need to supply the correct path to your midi file. This question about how to check for file existence might also be helpful.
The error messages from pygame.mixer.music.load are different if the file format is not supported or non-existent:
>>> pygame.mixer.music.load("nonexistent.file")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pygame.error: Couldn't open 'nonexistent.file'
>>> pygame.mixer.music.load(r"c:\tmp\empty.file")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pygame.error: Couldn't read from RWops
>>> pygame.mixer.music.load(r"c:\tmp\robots.txt")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pygame.error: Module format not recognized
>>> pygame.mixer.music.load(r"C:\Windows\media\flourish.mid")
>>> pygame.mixer.music.play(-1, 0)
>>> pygame.mixer.music.stop()
Note that when specifying a file path a \ is an escape character which is processed differently. So you can use \\ instead, or put an r at the start of the string, before the quotation mark as I've shown above.
I have checked that the file in my disk is the same as https://github.com/scipy/scipy/blob/master/scipy/misc/face.dat
but when I run this statement ,I have got this error. why ?
scipy.misc.face()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\scipy\misc\common.py", line 567, in face
data = bz2.decompress(rawdata)
ValueError: couldn't find end of stream
It's a bug (on Windows), see here
https://github.com/scipy/scipy/commit/7f0210fd28a2b3be79806d5cae462be52c1601e9