I need to build a speech to text converter using Python and Google speech to text API. I want to do this real-time as in this example link. So far I have tried following code:
import speech_recognition as sr
import pyaudio
r= sr.Recognizer()
print("Running")
p = pyaudio.PyAudio()
for i in range(p.get_device_count()):
print(p.get_device_info_by_index(i))
with sr.Microphone(1) as source:
r.adjust_for_ambient_noise(source, 1) # Adjust for ambient
print("Say something!")
audio=r.listen(source)
print("Runnnnnn")
try:
print("Analyzing voice data "+r.recognize_google(audio, language='hi-IN'))
except Exception:
print("Something went wrong")
This code first listens through the microphone then it converts to the text format. What I want to achieve here is while listening it should start converting to text in real time instead of waiting for it to complete.