guys, i have a problem with speech recognition on python3.x
I using module speech_recognition.
My .wav file have length 5 minutes, however python recognized only first 5 seconds of this file.
I have never worked with this module.
Please, help me
My code
import speech_recognition as sr
r = sr.Recognizer()
with sr.AudioFile(r"C:\Users\User\Downloads\Unlocking.wav") as source:
audio = r.record(source)
text = r.recognize_google(audio)
print(text)
Related
I was trying to convert speech to text via pyaduio.The program was working fine for a few hours but suddenly my visual studio 2019 keeps on marking an error in the 6th line for no reason.
Does anyone know how to fix it? tnx :)
import speech_recognition as sr
import pyaudio
r = sr.Recognizer()
mic = sr.Microphone(device_index=1)
with mic as source:
audio_data = r.record(source, duration= 3)
print("I recognize speaking")
text = r.recognize_google(audio_data)
print("I heard: ",text)
The problem was that google api is restricted to certain amount of uses without paying, and I ran out of free uses.
I have been working on converting speech to text using speech_recognition library on my Jupyter Notebook. All of a sudden, the code throws an error and I have no idea where to even start to solve this. The code is shown below:
import speech_recognition as sr
r = sr.Recognizer()
with sr.AudioFile('/audio1659122935.wav') as source:
audio_text = r.record(source)
try:
txt = r.recognize_google(audio_text)
print(text)
except:
print('Error... Try again...')
This generates the except message "Error... Try again..."
Did anyone have the same issue with using speech_recognition?
The speech_recognition version is 3.8.1 and my python version is 3.8.5
It was just a simple mistake using the wrong variable text. Also just unwrap the try except clause to see where the error occurs.
I want to determine, when exactly a speech in the audio file starts and ends. Firstly, I am using speech_recognition library to determine speech content of the audio file:
import speech_recognition as sr
filename = './dir_name/1.wav'
r = sr.Recognizer()
with sr.AudioFile(filename) as source:
audio_data = r.record(source)
text = r.recognize_google(audio_data, language = "en-US")
print(text)
Running this code I get a correct output (speech recognized content of the audio file). How can I determine, where exactly the speech starts and ends? Let's assume the file contains ONLY speech. I tried different methods, e. g. by analysing amplitude of the signal, its envelope etc. but I do not get high efficiency. So I started using speech_recognition library with a hope it could be useful here.
When i run this program the speech is recognized if I use a headset or an external microphone.
But, if I use the laptop microphone( Microphone Array (Realtek(R) Audio) ) the speech is not recognized. It's like the program hangs at the line audio = r.listen(source) If I say something and then plug in the headset then the program works.
The microphone in the laptop is working perfectly.
import speech_recognition as sr
import pyaudio
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening......")
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"USER: {query}\n")
except Exception:
print("Did not catch that")
Why id this happening? Can somebody help me out please?
Thank you.
r.adjust_for_ambient_noise(source)
I used this function and it's working now.
This increases the range to recognize the audio.
Thank you everyone.
I will guess.
Probably it uses external microphone as default device and you have to manually set other device.
In documentation you can see
Microphone(device_index = None)
And
A device index is an integer between 0 and pyaudio.get_device_count() - 1
You can also see how to get list of all available devices.
import speech_recognition as sr
for index, name in enumerate(sr.Microphone.list_microphone_names()):
print("Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))
BTW: You can also read Troubleshooting - maybe it gives more ideas.
I am working on speech recognition in python, but it is only getting the input from Micropohone. How is it possible to give the audio from speakers as input to the speech recognition library?
The piece of code is given below:
import speech_recognition as sr
with sr.Microphone() as source: # using microphone here, would like to use speaker instead
print("Talk Something...")
audio=r.listen(source)
print("Time Over...")
import time
try:
t1=time.time()
print("Text: "+r.recognize_google(audio)) # prints after converting speech to text
t2=time.time()
print("T2-T1: ", t2-t1)
except:
print("Didn't understand the audio")
I have been struggling here for so long and any help will be much appreciated. Thanks!
You can configure device index as in docs:
import speech_recognition as sr
for index, name in enumerate(sr.Microphone.list_microphone_names()):
print("Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))
If LINEIN is not available as a separate input, you might just configure it as a recording source in audio properties.