这段代码有什么问题?它没有显示任何错误,但也没有显示任何输出
What is wrong with this code ? It is not showing any error but It is also not showing any output
我正在尝试语音转文本程序。我已经编写了这段代码,但它没有显示任何输出,也没有显示任何错误。它不是在读我的演讲。找不到任何解决方案。请帮忙。
import speech_recognition as sr
import webbrowser as wb
r1 = sr.Recognizer()
r2 = sr.Recognizer()
with sr.Microphone() as source:
print('Say Hello')
print('Speak')
audio = r2.listen(source)
if 'Hello' in r1.recognize_google(audio):
r1 = sr.Recognizer()
url = 'https://www.google.com/'
with sr.Microphone() as source:
print('search')
audio = r1.listen(source)
try:
get = r1.recognize_google(audio)
print(get)
wb.get().open_new(url + get)
except sr.UnknownValueError:
print('Not recognised')
except sr.RequestError as e:
print('try again'.format(e))
在我冒着婚姻风险反复烦人地对着我的电脑大喊你好之后,看起来捕获的音频总是小写的:
Say Hello
Speak
> /Users/matt/repos/Whosebug/test.py(16)<module>()
-> if 'Hello' in audio_result:
(Pdb) l
11
12 audio_result = r1.recognize_google(audio)
13 import pdb; pdb.set_trace()
14
15
16 -> if 'Hello' in audio_result:
17
18 r1 = sr.Recognizer()
19 url = 'https://www.google.com/'
20 with sr.Microphone() as source:
21 print('search')
(Pdb) audio_result
'hello hello hello hello hello hello hello hello hello hello hello hello hello hello'
(Pdb) 'Hello' in audio_result
False
(Pdb) 'hello' in audio_result
True
很明显 'Hello'
应该是 'hello'
。
切换并重试后,我的浏览器打开 url https://www.google.com/hello,但没有解决,但我认为这会让你更进一步。
HTH.
我正在尝试语音转文本程序。我已经编写了这段代码,但它没有显示任何输出,也没有显示任何错误。它不是在读我的演讲。找不到任何解决方案。请帮忙。
import speech_recognition as sr
import webbrowser as wb
r1 = sr.Recognizer()
r2 = sr.Recognizer()
with sr.Microphone() as source:
print('Say Hello')
print('Speak')
audio = r2.listen(source)
if 'Hello' in r1.recognize_google(audio):
r1 = sr.Recognizer()
url = 'https://www.google.com/'
with sr.Microphone() as source:
print('search')
audio = r1.listen(source)
try:
get = r1.recognize_google(audio)
print(get)
wb.get().open_new(url + get)
except sr.UnknownValueError:
print('Not recognised')
except sr.RequestError as e:
print('try again'.format(e))
在我冒着婚姻风险反复烦人地对着我的电脑大喊你好之后,看起来捕获的音频总是小写的:
Say Hello
Speak
> /Users/matt/repos/Whosebug/test.py(16)<module>()
-> if 'Hello' in audio_result:
(Pdb) l
11
12 audio_result = r1.recognize_google(audio)
13 import pdb; pdb.set_trace()
14
15
16 -> if 'Hello' in audio_result:
17
18 r1 = sr.Recognizer()
19 url = 'https://www.google.com/'
20 with sr.Microphone() as source:
21 print('search')
(Pdb) audio_result
'hello hello hello hello hello hello hello hello hello hello hello hello hello hello'
(Pdb) 'Hello' in audio_result
False
(Pdb) 'hello' in audio_result
True
很明显 'Hello'
应该是 'hello'
。
切换并重试后,我的浏览器打开 url https://www.google.com/hello,但没有解决,但我认为这会让你更进一步。
HTH.