2017-08-31 84 views
3

使用腹圍在使用腹圍谷歌翻譯模塊在Python 2.x中,我得到錯誤 -得到的Unicode解碼錯誤而在蟒蛇

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gtts/tts.py", line 94, in init if self._len(text) <= self.MAX_CHARS: File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gtts/tts.py", line 154, in _len return len(unicode(text)) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)`.

即使我已經包括在我的python腳本# -*- coding: utf-8 -*-,我得到關於使用非ASCII字符的錯誤。告訴我一些其他的實現方式,比如我可以用英語寫句子並用其他語言翻譯。但是,由於我正在用英語發言,所以這也不起作用,只改變口音。

我已經搜遍很多地方,但無法找到答案。請幫忙!

回答

1

我曾嘗試以unicode格式編寫一個字符串作爲- u'Qu'est-ce que tu fais? Gardez-le de côté.'

將ASCII碼字符轉換爲unicode格式,從而解決錯誤。所以,你想要轉換成語音的文本甚至可以有utf-8格式的字符,並且可以很容易地轉換。

0

您還需要輸入參數的gtts-cli.py

變化從這個以下行解碼:

if args.text == "-": 
    text = sys.stdin.read() 
else: 
    text = arg.text 

這樣:

if args.text == "-": 
    text = sys.stdin.read() 
else: 
    text = codecs.decode(arg.text,"utf-8") 

對我的作品, 試一試。