这个代码怎么了?它没有显示任何错误,但也没有显示任何输出

2024-04-19 07:44:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试一个语音到文本的程序。我已经写了这段代码,但它没有显示任何输出,也没有显示任何错误。不是在读我的演讲稿。找不到解决办法。请帮忙。你知道吗

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))

Tags: importsourcehellogetaswithgoogleaudio
1条回答
网友
1楼 · 发布于 2024-04-19 07:44:09

在我冒着婚姻的危险,在我的电脑前不停地、恼人地喊“你好”之后,捕捉到的音频看起来总是小写的:

Say Hello
Speak
> /Users/matt/repos/stackoverflow/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'。你知道吗

在切换和重试之后,我的浏览器打开到urlhttps://www.google.com/hello,但没有解析,但我想这会让你走得更远。你知道吗

嗯。你知道吗

相关问题 更多 >