I have made a working speech to text program using the google speech to text api that records speech and copies it into a .txt however, the Google speech api does not listen for very long (approx 9 seconds) is there any way to increase this, or a better api for use in python that can write while listening?
import time
import speech_recognition as sr
import sys
import fileinput
r=sr.Recognizer()
#tells the program to use a mic and to listen
with sr.Microphone() as source:
audio=r.listen(source)
#asking the program to try to listen
try:
spoken = r.recognize_google(audio)
print("I heard:"+spoken)
except Exception:
print ("Somthing went wrong")
#writing what was recorded by the mic into a .txt
with open("name-of-file.txt", "a") as f:
f.write("\n")
f.write(time.strftime("%H:%M:%S") + " " + time.strftime("%d/%m/%Y"))
f.write("\n")
f.write(spoken)
Expected result: The program listens and writes at the same time or The program can listen until turned off. Actual result: The program listens for about 9 seconds and then prints to .txt