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))
Related
I'm just trying to create a simple speech to text transcriber using the openai whisper module and streamlit for web application but having some problems.
It is giving me error
Traceback (most recent call last):
File "C:\Users\Satyam Singh\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 565, in _run_script
exec(code, module.__dict__)
File "C:\Users\Satyam Singh\Desktop\Python Project\app.py", line 19, in <module>
transcription = model.transcribe(audio_file)
File "C:\Users\Satyam Singh\AppData\Local\Programs\Python\Python310\lib\site-packages\whisper\transcribe.py", line 84, in transcribe
mel = log_mel_spectrogram(audio)
File "C:\Users\Satyam Singh\AppData\Local\Programs\Python\Python310\lib\site-packages\whisper\audio.py", line 112, in log_mel_spectrogram audio = torch.from_numpy(audio)
**TypeError: expected np.ndarray (got NoneType)**
Here's my code
import streamlit as st
import whisper
from audio_recorder_streamlit import audio_recorder
# App Title Name
st.title("Speech to Text")
# uploading an audio file
# audio_file = st.file_uploader("Upload Audio", type=["wav","mp3","m4a"])
audio_file = audio_recorder()
if audio_file:
st.audio(audio_file, format="audio/wav")
model = whisper.load_model("base")
st.text("Whisper Model Loaded")
transcription = model.transcribe(audio_file)
print(transcription['text'])
if st.sidebar.button("Transcribe Audio"):
if audio_file is not None:
st.sidebar.success("Transcribing Audio")
transcription = model.transcribe(audio_file.name)
st.sidebar.success("Transcription Complete")
st.text(transcription["text"])
else:
st.sidebar.error("Please Upload an Audio File")
I want something like Baseten
I want this code to work or something more innovative which works same way like this one or Baseten.
I am trying to implement a background listing using speech_recognition python library. Following code use for that. When I run this code I got the following error message. How can I solve this issue?
Error MSG:
RuntimeError: Decoder_set_kws returned -1
Python library - https://github.com/Uberi/speech_recognition#readme
Code:
import speech_recognition as sr
import time
r = sr.Recognizer()
# Words that sphinx should listen closely for. 0-1 is the sensitivity
# of the wake word.
keywords = [("google", 1), ("hey google", 1), ]
source = sr.Microphone(device_index = device_id, sample_rate = sample_rate, chunk_size = chunk_size)
def callback(recognizer, audio): # this is called from the background thread
try:
speech_as_text = recognizer.recognize_sphinx(audio, keyword_entries=keywords)
print(speech_as_text)
# Look for your "Ok Google" keyword in speech_as_text
if "google" in speech_as_text or "hey google":
recognize_main()
except sr.UnknownValueError:
print("Oops! Didn't catch that")
def recognize_main():
print("Recognizing Main...")
audio_data = r.listen(source)
# interpret the user's words however you normally interpret them
def start_recognizer():
print("Main...")
r.listen_in_background(source, callback)
time.sleep(1000000)
start_recognizer()
Full Error MSG:
Exception in thread Thread-6: Traceback (most recent call last):
File "C:\Users\aa\anaconda3\envs\env1\lib\threading.py", line 926, in
_bootstrap_inner
self.run() File "C:\Users\aa\anaconda3\envs\env1\lib\threading.py", line 870, in run
self._target(*self.args, **self.kwargs) File "C:\Users\aa\anaconda3\envs\env1\lib\site-packages\speech_recognition_init.py",
line 616, in threaded_listen
if running[0]: callback(self, audio) File "", line 16, in callback
speech_as_text = recognizer.recognize_sphinx(audio, keyword_entries=keywords) File
"C:\Users\aa\anaconda3\envs\env1\lib\site-packages\speech_recognition_init.py",
line 683, in recognize_sphinx
decoder.set_kws("keywords", f.name) File "C:\Users\aa\anaconda3\envs\env1\lib\site-packages\pocketsphinx\pocketsphinx.py",
line 309, in set_kws
return _pocketsphinx.Decoder_set_kws(self, name, keyfile) RuntimeError: Decoder_set_kws returned -1
My computer is Windows 10 version:10.0.19041 python version:3.9
My code:
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
voice = r.recognize_google(audio)
print(voice)
Traceback
Traceback (most recent call last):
File "C:\Users\mt7da\Alexa.py", line 7, in <module>
voice = r.recognize_google(audio)
File "C:\Users\mt7da\AppData\Local\Programs\Python\Python39\lib\site-packages\speech_recognition\__init__.py", line 858, in recognize_google
if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()
speech_recognition.UnknownValueError
```*
*İf you need ```__init__.py``` it is here`[http://file:///C:/Users/mt7da/AppData/Local/Programs/Python/Python39/Lib/site-packages/speech_recognition/__init__.py][1]`**
[1]:
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'>
I got some code from google for speech recognition when i try to run that code i'm getting "NotImplementedError" please see the below code and help me.I'm using Mac.
import speech_recognition as sr
r = sr.Recognizer()
with sr.Recognizer() as source:
print("Speak Anything")
audio = r.listen(source)
try:
text = r.recognize_google(audio)
print("you said:{}".format(text))
except NotImplementedError:
print("Sorry could not recognise your voice")
Traceback (most recent call last):
File "", line 4, in
with sr.Recognizer() as source:
File "/Users/chiku/anaconda3/lib/python3.5/site-packages/speech_recognition/init.py", line 51, in enter
raise NotImplementedError("this is an abstract class")
NotImplementedError: this is an abstract class
Traceback (most recent call last):
File "", line 4, in
with sr.Recognizer() as source:
File "/Users/chiku/anaconda3/lib/python3.5/site-packages/speech_recognition/init.py", line 51, in enter
raise NotImplementedError("this is an abstract class")
NotImplementedError: this is an abstract class
In the line above, you instantiate a Recognizer object, then you try to use the uninstatiated class in the problem line. Should that be
with r as source:
...
I have the below code and it gives me same error i.e
Traceback (most recent call last):
File "/Users/../Listen.py", line 25, in
print(Listen())
^^^^^^^^
File "/Users/../Listen.py", line 8, in Listen
with sr.Recognizer() as source:
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/speech_recognition/init.py", line 51, in enter
raise NotImplementedError("this is an abstract class")
NotImplementedError: this is an abstract class
import speech_recognition as sr
from googletrans import Translator
def Listen():
r = sr.Microphone()
with sr.Recognizer() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='hi')
except:
return ""
query = str(query).lower()
return query
Listen()