我无法使用带有语音识别的 urllib 进行搜索(我是初学者)
我正在尝试在网站中搜索字符串,但无法搜索。
import speech_recognition as sr
import urllib
import urllib.request
import re
page = urllib.request.urlopen("https://en.wikipedia.org/wiki/Main_Page").read()
r = sr.Recognizer()
with sr.Microphone() as source:
print("say something: ")
audio = r.listen(source)
flag = False
try:
print("you said: " + r.recognize_google(audio,))
flag = True
except sr.UnknownValueError:
print("error")
except sr.RequestError as e:
print("error; {0}".format(e))
if flag:
re.findall(r.recognize_google(audio), page)
page.find(r.recognize_google(audio))
else:
print("error")
错误是
return _compile(pattern, flags).findall(string) 类型错误:无法在类似字节的对象上使用字符串模式
I'm trying to search a string in a website but just can't..
import speech_recognition as sr
import urllib
import urllib.request
import re
page = urllib.request.urlopen("https://en.wikipedia.org/wiki/Main_Page").read()
r = sr.Recognizer()
with sr.Microphone() as source:
print("say something: ")
audio = r.listen(source)
flag = False
try:
print("you said: " + r.recognize_google(audio,))
flag = True
except sr.UnknownValueError:
print("error")
except sr.RequestError as e:
print("error; {0}".format(e))
if flag:
re.findall(r.recognize_google(audio), page)
page.find(r.recognize_google(audio))
else:
print("error")
error is
return _compile(pattern, flags).findall(string)
TypeError: cannot use a string pattern on a bytes-like object
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论