【发布时间】:2019-01-08 17:56:38
【问题描述】:
我已经使用 google Speech to text api 制作了一个工作语音到文本程序,它记录语音并将其复制到 .txt 但是,Google Speech api 不会听很长时间(大约 9 秒)有什么办法增加这个,或者在 python 中使用更好的 api 可以边听边写?
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)
预期结果: 程序边听边写 或者 该程序可以收听直到关闭。 实际结果: 程序监听大约 9 秒,然后打印到 .txt
【问题讨论】: