The Code:
import speech_recognition as sr
file_name = "tts.wav"
speech_engine = sr.Recognizer()
def from_file(file_name):
with sr.AudioFile(file_name) as f:
data = speech_engine.record(f)
text = speech_engine.recognize_google(data, language="de-DE")
return text
def from_microphone():
with sr.Microphone() as micro:
print("Recording...")
audio = speech_engine.record(micro, duration=5)
print("Recognition...")
text = speech_engine.recognize_google(audio, language="de-DE")
return text
from_file(file_name)
print(from_microphone())
Terminal:
PS C:\Users\schne\Desktop\Jarvis> &
C:/Users/schne/AppData/Local/Microsoft/WindowsApps/python3.10.exe
"c:/Users/schne/Desktop/Jarvis/speech to text copy.py" Traceback (most
recent call last): File
"C:\Users\schne\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\speech_recognition_init_.py",
line 253, in enter
self.audio_reader = wave.open(self.filename_or_fileobject, "rb") File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\wave.py",
line 509, in open
return Wave_read(f) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\wave.py",
line 163, in init
self.initfp(f) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\wave.py",
line 130, 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\schne\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\speech_recognition_init_.py",
line 258, in enter
self.audio_reader = aifc.open(self.filename_or_fileobject, "rb") File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\aifc.py",
line 917, in open
return Aifc_read(f) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\aifc.py",
line 352, in init
self.initfp(file_object) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\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\schne\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\speech_recognition_init_.py",
line 284, in enter
self.audio_reader = aifc.open(aiff_file, "rb") File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\aifc.py",
line 917, in open
return Aifc_read(f) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\aifc.py",
line 358, in init
self.initfp(f) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\aifc.py",
line 314, in initfp
chunk = Chunk(file) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\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\schne\Desktop\Jarvis\speech to text copy.py", line 17, in
from_file(file_name) File "c:\Users\schne\Desktop\Jarvis\speech to text copy.py", line 5, in from_file
with sr.AudioFile(file_name) as f: File "C:\Users\schne\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\speech_recognition_init_.py",
line 286, 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
The program should recognize text from a file or directly from the microphone, but the terminal does not recognize it or something (I'm a beginner).
Related
I write a little program which writes the audio to text. But it throws an error and I don't know how to fix it.
import speech_recognition as sr
file_name = "halloWelt.wav"
speech_engine = sr.Recognizer()
with sr.AudioFile(file_name) as file:
data = speech_engine.record()
text = speech_engine.recognize_google(data, language='de-DE')
print(text)
The error:
Traceback (most recent call last):
File "C:\Users\\AppData\Local\Programs\Python\Python310\lib\site-packages\speech_recognition\__init__.py", line 203, in __enter__
self.audio_reader = wave.open(self.filename_or_fileobject, "rb")
File "C:\Users\\AppData\Local\Programs\Python\Python310\lib\wave.py", line 509, in open
return Wave_read(f)
File "C:\Users\\AppData\Local\Programs\Python\Python310\lib\wave.py", line 163, in __init__
self.initfp(f)
File "C:\Users\\AppData\Local\Programs\Python\Python310\lib\wave.py", line 130, 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\\AppData\Local\Programs\Python\Python310\lib\site-packages\speech_recognition\__init__.py", line 208, in __enter__
self.audio_reader = aifc.open(self.filename_or_fileobject, "rb")
File "C:\Users\\AppData\Local\Programs\Python\Python310\lib\aifc.py", line 917, in open
return Aifc_read(f)
File "C:\Users\\AppData\Local\Programs\Python\Python310\lib\aifc.py", line 352, in __init__
self.initfp(file_object)
File "C:\Users\\AppData\Local\Programs\Python\Python310\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\\AppData\Local\Programs\Python\Python310\lib\site-packages\speech_recognition\__init__.py", line 234, in __enter__
self.audio_reader = aifc.open(aiff_file, "rb")
File "C:\Users\\AppData\Local\Programs\Python\Python310\lib\aifc.py", line 917, in open
return Aifc_read(f)
File "C:\Users\\AppData\Local\Programs\Python\Python310\lib\aifc.py", line 358, in __init__
self.initfp(f)
File "C:\Users\\AppData\Local\Programs\Python\Python310\lib\aifc.py", line 314, in initfp
chunk = Chunk(file)
File "C:\Users\\AppData\Local\Programs\Python\Python310\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\\OneDrive\Dokumente\Programming\Python\Lets code\speech.py", line 6, in <module>
with sr.AudioFile(file_name) as file:
File "C:\Users\\AppData\Local\Programs\Python\Python310\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
I'm running a python script that is supposed to listen tweets with a specific '#' (and then execute some code).
My code is almost running 100% correctly but I still have an issue: my program stops running at random time for "no reason".
Here is the error:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/http/client.py", line 551, in _get_chunk_left
chunk_left = self._read_next_chunk_size()
File "/usr/local/lib/python3.8/http/client.py", line 518, in _read_next_chunk_size
return int(line, 16)
ValueError: invalid literal for int() with base 16: b''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/http/client.py", line 583, in _readinto_chunked
chunk_left = self._get_chunk_left()
File "/usr/local/lib/python3.8/http/client.py", line 553, in _get_chunk_left
raise IncompleteRead(b'')
http.client.IncompleteRead: IncompleteRead(0 bytes read)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 436, in _error_catcher
yield
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 518, in read
data = self._fp.read(amt) if not fp_closed else b""
File "/usr/local/lib/python3.8/http/client.py", line 454, in read
n = self.readinto(b)
File "/usr/local/lib/python3.8/http/client.py", line 488, in readinto
return self._readinto_chunked(b)
File "/usr/local/lib/python3.8/http/client.py", line 599, in _readinto_chunked
raise IncompleteRead(bytes(b[0:total_bytes]))
http.client.IncompleteRead: IncompleteRead(292 bytes read)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 133, in <module>
myStream.filter(track=['#DownDropship'])
File "/usr/local/lib/python3.8/site-packages/tweepy/streaming.py", line 474, in filter
self._start(is_async)
File "/usr/local/lib/python3.8/site-packages/tweepy/streaming.py", line 389, in _start
self._run()
File "/usr/local/lib/python3.8/site-packages/tweepy/streaming.py", line 320, in _run
six.reraise(*exc_info)
File "/usr/local/lib/python3.8/site-packages/six.py", line 703, in reraise
raise value
File "/usr/local/lib/python3.8/site-packages/tweepy/streaming.py", line 289, in _run
self._read_loop(resp)
File "/usr/local/lib/python3.8/site-packages/tweepy/streaming.py", line 339, in _read_loop
line = buf.read_line()
File "/usr/local/lib/python3.8/site-packages/tweepy/streaming.py", line 200, in read_line
self._buffer += self._stream.read(self._chunk_size)
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 540, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/usr/local/lib/python3.8/contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 454, in _error_catcher
raise ProtocolError("Connection broken: %r" % e, e)
urllib3.exceptions.ProtocolError: ('Connection broken: IncompleteRead(292 bytes read)', IncompleteRead(292 bytes read))
Here is a piece of my code:
from tweepy import StreamListener
from retrying import retry
import tweepy
#retry
class MyStreamListener(StreamListener):
#retry
def on_status(self, status):
do something ...
except Exception as e:
pass
myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth=twitter_handler.api.auth, listener=myStreamListener)
myStream.filter(track=['#Something'])
I found these "#retry" here but apparently, it doesn't work properly.
Thanks for your help
I try to load a umap_2.sav with the same environment with which I create the file but on another PC. I get an EOFError by using 50% of my memory.
umap_model_plot = umap.UMAP(n_neighbors=15,
n_components=2,
metric='cosine', low_memory=True).fit(emb)
joblib.dump(umap_model_plot,'umap_2.sav')
On a other pc
umap_model_plot = joblib.load('umap_2.sav')
Error
umap_model_plot = joblib.load('umap_2.sav')
Traceback (most recent call last):
File "<ipython-input-5-f6a4b963c45a>", line 1, in <module>
umap_model_plot = joblib.load('umap_2.sav')
File "C:\Users\Administrator\anaconda3\envs\top2vec_final_\lib\site-packages\joblib\numpy_pickle.py", line 585, in load
obj = _unpickle(fobj, filename, mmap_mode)
File "C:\Users\Administrator\anaconda3\envs\top2vec_final_\lib\site-packages\joblib\numpy_pickle.py", line 504, in _unpickle
obj = unpickler.load()
File "C:\Users\Administrator\anaconda3\envs\top2vec_final_\lib\pickle.py", line 1086, in load
raise EOFError
EOFError
My goal is to receive an audio file from client and transcribe it to text without permanently saving to disk. I'm using SpeechRecognition library and it works perfectly if uploaded file is saved, but when i try to use temporary file it leads to error.
From CherryPy docs:
When a client uploads a file to a CherryPy application, it’s placed on disk immediately. CherryPy will pass it to your exposed method as an argument; that arg will have a “file” attribute, which is a handle to the temporary uploaded file
Since the sr.AudioFile constructor also accepts a 'file-like object', i'm using io.BytesIO to pass the content of temporary file to constructor.
Here's the code of my server:
import io
import cherrypy
import speech_recognition as sr
class HttpServer(object):
#cherrypy.expose
def index(self, ufile):
ufile_content = ufile.file.read() # reading temp file
buffer = io.BytesIO(ufile_content)
buffer.seek(0)
with sr.AudioFile(buffer) as source:
audio = self.recognizer.record(source)
result = self.recognizer.recognize_google(audio, language='ru-RU')
I'm using this code to send request to the server:
import requests
url = 'http://localhost:8080/'
files = {'ufile': ('audio.flac', open('audio.flac', 'rb'), 'audio/flac')}
r = requests.post(url, files=files)
I get the following error:
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 203, in __enter__
self.audio_reader = wave.open(self.filename_or_fileobject, "rb")
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\lib\wave.py", line 510, in open
return Wave_read(f)
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\lib\wave.py", line 164, in __init__
self.initfp(f)
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\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\Артём\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 208, in __enter__
self.audio_reader = aifc.open(self.filename_or_fileobject, "rb")
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\lib\aifc.py", line 917, in open
return Aifc_read(f)
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\lib\aifc.py", line 358, in __init__
self.initfp(f)
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\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\Артём\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 234, in __enter__
self.audio_reader = aifc.open(aiff_file, "rb")
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\lib\aifc.py", line 917, in open
return Aifc_read(f)
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\lib\aifc.py", line 358, in __init__
self.initfp(f)
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\lib\aifc.py", line 314, in initfp
chunk = Chunk(file)
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\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\Артём\AppData\Local\Programs\Python\Python37\lib\site-packages\cherrypy\_cprequest.py", line 628, in respond
self._do_respond(path_info)
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\lib\site-packages\cherrypy\_cprequest.py", line 687, in _do_respond
response.body = self.handler()
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\lib\site-packages\cherrypy\lib\encoding.py", line 219, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\lib\site-packages\cherrypy\_cpdispatch.py", line 54, in __call__
return self.callable(*self.args, **self.kwargs)
File "new1.py", line 19, in index
with audio_file as source:
File "C:\Users\Артём\AppData\Local\Programs\Python\Python37\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
Does anyone have any solutions to the problem?
devignesh#devignesh:~/soup$ pip list
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2556, in version
return self._version
File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2663, in __getattr__
raise AttributeError(attr)
AttributeError: _version
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pip/_internal/basecommand.py", line 141, in main
status = self.run(options, args)
File "/usr/local/lib/python3.5/dist-packages/pip/_internal/commands/list.py", line 143, in run
self.output_package_listing(packages, options)
File "/usr/local/lib/python3.5/dist-packages/pip/_internal/commands/list.py", line 208, in output_package_listing
data, header = format_for_columns(packages, options)
File "/usr/local/lib/python3.5/dist-packages/pip/_internal/commands/list.py", line 274, in format_for_columns
row = [proj.project_name, proj.version]
File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2561, in version
raise ValueError(tmpl % self.PKG_INFO, self)
ValueError: ("Missing 'Version:' header and/or METADATA file", Unknown [unknown version] (/home/devignesh/.local/lib/python3.5/site-packages))
devignesh#devignesh:~/soup$