How to use Google Translate in Matlab?

守給你的承諾、 提交于 2019-12-07 03:44:45

问题


I am writing a program to list all unique words in a movie subtitle file using Matlab. Now I have a unique word list that I want to translate to my language and learn the meaning before watching the movie.

Does anyone know how can I use Google Translate in Matlab so that I can complete my script? Is there any web service or so, and how can I use it in Matlab?

Thanks,


Appendix 1: I have found this code useful:

%build url and send to google
url = 'http://ajax.googleapis.com/ajax/services/language/translate';
page = urlread(url, 'get', {'v', '1.0','q', inputString,'langpair', [sourceLanguage '|' destLanguage]});

but I don't know why it returns error each time I run it (e.g. 403 or 400). I know that my internet connection is okay when testing.


回答1:


For a simple translator (I have no idea about quality), maybe try this. I didn't bother parsing the output:

langCodes = urlread('http://www.transltr.org/api/getlanguagesfortranslate'); % find your language code

textToTranslate = 'rabbit'; %change

langCodeOfOrigText ='en';
langCodeOfTranslation ='es';

translateURL = 'http://www.transltr.org/api/translate';
translateResults = urlread(translateURL, 'get', {'text',textToTranslate,'to',langCodeOfTranslation,'from',langCodeOfOrigText});

Just see next to translationText of the output for the result. Like I said, you can parse it, just google for a json to matlab struct parser.



来源:https://stackoverflow.com/questions/44065795/how-to-use-google-translate-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!