Traceback (most recent call last):
File "yuyin.py", line 17, in <module>
if '關閉'.encode("utf-8") in info:
TypeError: 'in <string>' requires string as left operand, not bytes
運行下面代碼,出現上述錯誤,請大佬指點一下,感激不盡
# coding: utf-8
import os
import time
import yuyinhecheng
import Tuling
import yuyinshibie
tok = yuyinshibie.get_access_token()
switch = True
while switch:
os.system('sudo arecord -D plughw:2,0 -f cd /home/pi/Desktop/voice.wav')
time.sleep(0.5)
info = yuyinshibie.asr_main("/home/pi/Desktop/voice.wav",tok)
if '關閉'.encode("utf-8") in info:
while True:
os.system('sudo arecord -D plughw:2,0 -f cd /homme/pi/Desktop/voice.wav')
time.sleep(10)
info = yuyinshibie.asr_main("/home/pi/Desktop/voice.wav",tok)
if '開啟'.encode("utf-8") in info:
break
url = "http://tsn.baidu.com/text2audio?tex=開啟成功&lan=zh&cuid=B8-27-EB-BA-24-14&ctp=1&tok="+tok+"&per=3"
os.system('mpg123 "%s"'%url)
elif '暫停'.encode("utf-8") in info:
url = "http://tsn.baidu.com/text2audio?tex=開始暫停&lan=zh&cuid=B8-27-EB-BA-24-14&ctp=1&tok="+tok+"&per=3"
os.system('mpg123 "%s"'%url)
time.sleep(10)
url = "http://tsn.baidu.com/text2audio?tex=暫停結束&lan=zh&cuid=B8-27-EB-BA-24-14&ctp=1&tok="+tok+"&per=3"
os.system('mpg123 "%s"'%url)
continue
else:
tex = Tuling.Tuling(info)
url = yuyinhecheng.yuyinhecheng_api(tok,tex)
os.system('mpg123 "%s"'%url)
time.sleep(0.5)
uj5u.com熱心網友回復:
從報錯看,說'關閉'.encode("utf-8")不應該是byte型別,而是str型別。這個'關閉'.encode("utf-8")直接寫成字串'\xe5\x85\xb3\xe9\x97\xad'可不可以?不知道你的邏輯
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/243003.html
上一篇:python 同步代碼改成異步的:各位大佬,下面是我寫的讀取tushare股票價格的大碼,因為有多只股票,寫成異步的,但是我寫的代碼執行后的效果還是同步的效果,
