忘了自己是 2021-04-08 11:56 采纳率: 50%
浏览 795
已采纳

'in <string>' requires string as left operand

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
  • 写回答

2条回答 默认 最新

  • CSDN专家-HGJ 2021-04-08 14:44
    关注

    错误提示很清楚,在 str in str 表达式中,左边也应该是个str,而你代码中in左边的是bytes,不是str类型,再用decode()转换一下。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作