Skip to content

print googleSpeechURL: ordinal not in range(128) #1

@IL2

Description

@IL2

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions