File "HJ.py", line 20, in yuyinhx
if any(['好'.encode("utf-8")in meg,'你'.encode("utf-8")in meg,"你好".encode("utf-8")in meg,"您".encode("utf-8")in meg]):
TypeError: 'in <string>' requires string as left operand, not bytes
代码
def yuyinhx():
os.system('arecord -D "plughw:1" -f S16_LE -r 16000 -d 3 /home/pi/Desktop/yyhx.wav')
meg =yuyinshibie.asr_main("/home/pi/Desktop/yyhx.wav",token)
if any(['好'.encode("utf-8")in meg,'你'.encode("utf-8")in meg,"你好".encode("utf-8")in meg,"您".encode("utf-8")in meg]):
f=open('/home/pi/Desktop/yyhx.wav','wb')
f.close()
url="http://tsn.baidu.com/text2audio?tex=我来啦&lan=zh&cuid=B8-27-EB-BA-24-14&ctp=1&tok="+token+"&per=3"
os.system('mpg123 "%s"'%url)
global flag
flag = True
错误提示很清楚,在 str in str 表达式中,左边也应该是个str,而你代码中in左边的是bytes,不是str类型,再用decode()转换一下。
您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632