我一直在使用谷歌语音识别的Python。下面是我的代码:
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
print(r.recognize_google(audio))
虽然识别非常准确,但它需要大约4-5秒才能吐出识别出的文本。因为我正在创建一个语音助手,所以我想修改上面的代码,以使语音识别速度更快。
有没有办法把这个数字降到大约1-2秒?如果可能的话,我正在尝试像Siri和Ok Google这样的服务一样快地获得认可。
我是python的新手,所以很抱歉我的问题有一个简单的答案。
发布于 2018-11-14 19:58:35
你可以使用另一个语音识别程序。例如,您可以在IBM设置一个帐户,以便使用他们的Watson Speech to Text。如果可能的话,试着使用他们的websocket接口,因为它会在你还在说话的时候积极地转录你所说的话。
一个例子(不使用websockets)如下:
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Adjusting for background noise. One second")
r.adjust_for_ambient_noise(source)
print("Say something!")
audio = r.listen(source)
IBM_USERNAME = "INSERT IBM SPEECH TO TEXT USERNAME HERE" # IBM Speech to Text usernames are strings of the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
IBM_PASSWORD = "INSERT IBM SPEECH TO TEXT PASSWORD HERE" # IBM Speech to Text passwords are mixed-case alphanumeric strings
try:
print("IBM Speech to Text thinks you said " + r.recognize_ibm(audio, username=IBM_USERNAME, password=IBM_PASSWORD))
except sr.UnknownValueError:
print("IBM Speech to Text could not understand audio")
except sr.RequestError as e:
print("Could not request results from IBM Speech to Text service; {0}".format(e))
你也可以尝试使用pocketsphinx,但就我个人而言,我对它没有特别好的体验。它是离线的(一个加号),但对我来说,并不是特别准确。您可能会调整一些检测设置,并消除一些背景噪音。我相信也有一个训练选项可以将其修改为您的声音,但它看起来并不简单。
一些有用的链接:
Microphone recognition example
祝好运。一旦语音识别正确工作,它是非常有用和有价值的!
发布于 2020-03-20 22:37:14
使用适当的输入通道和调整以获得最佳效果:
def speech_to_text():
required=-1
for index, name in enumerate(sr.Microphone.list_microphone_names()):
if "pulse" in name:
required= index
r = sr.Recognizer()
with sr.Microphone(device_index=required) as source:
r.adjust_for_ambient_noise(source)
print("Say something!")
audio = r.listen(source, phrase_time_limit=4)
try:
input = r.recognize_google(audio)
print("You said: " + input)
return str(input)
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
https://stackoverflow.com/questions/50548088
复制相似问题