Spoken translations in Emacs
Posted July 01, 2015 at 11:42 AM | categories: speech, emacs | tags:
Finally, continuing our experiments with computer speech for fun, let us try a translation of text to another language that is then spoken. Here is a free translator that has the courtesy to reply with json with the translated text in it. http://mymemory.translated.net/api/get?q=Hello%20World!&langpair=en|de I had to download a German voice called Anna, then get some translated text.
As with previous posts, there is a video: https://www.youtube.com/watch?v=8CBKnahE0ak . I am trying ScreenFlow for these (instead of Camtasia), and I still have not quite mastered the aspect ratio, so the videos still look a little odd.
As a reminder, we have this easy way to speak text in applescript. If you are on Linux, check out Festival and on windows you may find some inspiration here .
(do-applescript "say \"Hello. My name is John. I am glad to meet you.\"")
You can retrieve json data of the translated text, and then we can use it in our word-speak function we previously developed. Here is an example in in German.
(let* ((words-voice "Anna") (text "Hello. My name is John. I am glad to meet you.") (url (format "http://mymemory.translated.net/api/get?q=%s!&langpair=en|de" text)) (json (with-current-buffer (url-retrieve-synchronously url) (json-read-from-string (buffer-substring url-http-end-of-headers (point-max))))) (translated-text (cdr (assoc 'translatedText (cdr (assoc 'responseData json)))))) (words-speak translated-text) translated-text)
"Hallo. Mein Name ist John. Ich freue mich, Sie kennen zu lernen.!"
How about Chinese? Again, I downloaded a Chinese voice called "Ting-Ting".
(let* ((words-voice "Ting-Ting") (text "Hello. My name is John. I am glad to meet you.") (url (format "http://mymemory.translated.net/api/get?q=%s!&langpair=en|zh" text)) (json (with-current-buffer (url-retrieve-synchronously url) (json-read-from-string (buffer-substring url-http-end-of-headers (point-max))))) (translated-text (cdr (assoc 'translatedText (cdr (assoc 'responseData json)))))) (words-speak translated-text) translated-text)
"你好。我的名字是约翰。我很高兴见到你。!"
So, can any Chinese readers and listeners confirm if the text translates correctly, and if Ting-Ting said it correctly? Hopefully it is good enough to make some sense and be useful!
Copyright (C) 2015 by John Kitchin. See the License for information about copying.
Org-mode version = 8.2.10