Home > other >  TypeError: 'in the <string>' requires a string as the left operand, not bytes
TypeError: 'in the <string>' requires a string as the left operand, not bytes

Time:01-01

Traceback (the most recent call last) :
The File "yuyin. Py, line 17, in & lt; module>
If the 'closed'. Encode (" utf-8 ") in the info:
TypeError: 'the in & lt; String> 'the requires a string as the left operand, not bytes
Run the following code, this error, please bosses to give directions, thank



# coding: utf-8

The import OS
The import time
The import yuyinhecheng
The import Tuling
The import yuyinshibie


Tok=yuyinshibie. Get_access_token ()

The switch=True
While the switch:
OS. The 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 the 'closed'. Encode (" utf-8 ") in the info:
While True:
OS. The 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 the 'open'. The encode (" utf-8 ") in the info:
Break

Url="http://tsn.baidu.com/text2audio? Tex=success & amp; LAN=zh& Cuid=B8-24-27 - EB - BA - 14 & amp; CTP=1 & amp; Tok="+ +" tok & amp; Per=3 "
OS. The system (' mpg123 "% s" '% url)


Elif 'suspend'. Encode (" utf-8 ") in the info:
Url="http://tsn.baidu.com/text2audio? Tex suspended starting=& amp; LAN=zh& Cuid=B8-24-27 - EB - BA - 14 & amp; CTP=1 & amp; Tok="+ +" tok & amp; Per=3 "
OS. The system (' mpg123 "% s" '% url)
Time. Sleep (10)

Url="http://tsn.baidu.com/text2audio? Tex=suspended end & amp; LAN=zh& Cuid=B8-24-27 - EB - BA - 14 & amp; CTP=1 & amp; Tok="+ +" tok & amp; Per=3 "
OS. The system (' mpg123 "% s" '% url)
The continue
The else:
Tex=Tuling. Tuling (info)
Url=yuyinhecheng. Yuyinhecheng_api (tok, Tex)
OS. The system (' mpg123 "% s" '% url)
Time. Sleep (0.5)





CodePudding user response:

Look from an error, says' closed '. Encode (" utf-8 ") should not be byte type, but the STR type,

The 'closed'. Encode (" utf-8 ") directly into the string '\ xe5 \ x85 \ xb2 \ xe9 \ x97 \ xad' can you? I don't know your logic

  • Related