Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting Unicode decode error while using gTTS in python

While using gTTS google translator module in python 2.x, I am getting error-

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)`.

Even though I have included # -*- coding: utf-8 -*- in my python script, I am getting the error on using Non-ASCII characters. Tell me some other way to implement like I can write sentence in English and get translated in other language. But this is also not working as I am getting speech in English, only accent changed.

I have searched a lot everywhere but can't find an answer. Please help!

like image 910
Vibhor Agarwal Avatar asked May 12 '26 05:05

Vibhor Agarwal


1 Answers

I have tried writing a string in unicode format as- u'Qu'est-ce que tu fais? Gardez-le de côté.'.

The ASCII code characters are converted into unicode format and hence, resolve the error. So, the text you want to be converted into speech can even have utf-8 format characters and can be easily transformed.

like image 73
Vibhor Agarwal Avatar answered May 15 '26 07:05

Vibhor Agarwal