PiTranslate icon indicating copy to clipboard operation
PiTranslate copied to clipboard

print googleSpeechURL: ordinal not in range(128)

Open IL2 opened this issue 12 years ago • 1 comments

I've ran into error $ python PiTranslate.py -o en -d ru -t "hello" Origin: en Destination: ru Text: hello Traceback (most recent call last): File "PiTranslate.py", line 53, in speakDestinationText(translation) File "PiTranslate.py", line 29, in speakDestinationText print googleSpeechURL UnicodeEncodeError: 'ascii' codec can't encode characters in position 50-55: ordinal not in range(128)

If you change print googleSpeechURL to print googleSpeechURL.encode("utf-8") this line goes fine, but next line fails: Origin: en Destination: ru Text: hello http://translate.google.com/translate_tts?tl=ru&q=Привет Traceback (most recent call last): File "PiTranslate.py", line 53, in speakDestinationText(translation) File "PiTranslate.py", line 30, in speakDestinationText subprocess.call(["mplayer",googleSpeechURL], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) File "/usr/lib/python2.7/subprocess.py", line 493, in call return Popen(_popenargs, *_kwargs).wait() File "/usr/lib/python2.7/subprocess.py", line 679, in init errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child raise child_exception TypeError: execv() arg 2 must contain only strings

Changing subprocess.call(["mplayer",googleSpeechURL], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) to subprocess.call(["mplayer",googleSpeechURL.encode("utf-8")], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) throws no error, but no translated speech played. I guess subprocess should be called with parameters encoded in the other way.

Sometimes it throws $ python PiTranslate.py -o en -d ru -t "hello" Origin: en Destination: ru Text: hello http://translate.google.com/translate_tts?tl=ru&q=TranslateApiException: Cannot find an active Azure Market Place Translator Subscription associated with the request credentials. : ID=XXXX.V2_Json.Translate.XXXXXXXX

IL2 avatar Nov 08 '13 04:11 IL2

I've made a pull request that fixes the encoding problem.

The Azure problem is fixed by going to https://datamarket.azure.com/dataset/1899a118-d202-492c-aa16-ba21c33c06cb and "buying" the first package for $0. That solved all my Azure problems!

jiserra avatar Feb 16 '14 17:02 jiserra