lkuza2 / java-speech-api

The J.A.R.V.I.S. Speech API is designed to be simple and efficient, using the speech engines created by Google to provide functionality for parts of the API. Essentially, it is an API written in Java, including a recognizer, synthesizer, and a microphone capture utility. The project uses Google services for the synthesizer and recognizer. While this requires an Internet connection, it provides a complete, modern, and fully functional speech API in Java.
GNU General Public License v3.0
535 stars 301 forks source link

Wrong translate token with multiply words #73

Closed saroyama closed 8 years ago

saroyama commented 8 years ago

Thanks for you job. I try to use GoogleTranslate class, when i use one keyword all works excelent, but if i try to translate two or more words, token is wrong and google return 403 error. Although @helen5106 php version generate correct token with multiply words, for example: green=764880.885612 green apple=367137.242333 // correct and java generated tokens: green=764880.885612 green apple=80012.462896 // wrong

Skylion007 commented 8 years ago

@dean1510 What are your thoughts on this issue? @saroyama Let me know if you can find where exactly the codes are differing (via a debugger or something) it likely has to due with a difference of order of operations between PHP and Java.

Unfortunately, I did not work too much on the token generation, but if you can find exactly at what line the code begins to differ, that would prove most helpful.

dean1510 commented 8 years ago

Problem isn't related to TK calculation algorithm. You should run it on original string: String encoded = URLEncoder.encode(text, "UTF-8"); //Encode At this time "green apple" is converted to "green+apple" ... sb.append(generateToken(encoded)); TK is calculated on converted string, not original source => You get an error.

Try use sb.append(generateToken(text)); instead.

Skylion007 commented 8 years ago

Thanks for the info. I submitted a bugfix and uploaded the latest binaries.

saroyama commented 8 years ago

@dean1510 I'm doing it exactly as you wrote, and i using original GoogleTranslate class without any changes from my side. But first url ok: http://translate.google.com/translate_a/single?client=t&hl=en&sl=en&tl=es&text=green&multires=1&otf=0&pc=0&trs=1&ssel=0&tsel=0&sc=1&dt=t&ie=UTF-8&oe=UTF-8&tk=825315.704312 Second, not: http://translate.google.com/translate_a/single?client=t&hl=en&sl=en&tl=es&text=green+apple&multires=1&otf=0&pc=0&trs=1&ssel=0&tsel=0&sc=1&dt=t&ie=UTF-8&oe=UTF-8&tk=514818.127961

Skylion007 commented 8 years ago

@saroyama New binaries seem to be working for me. Green Apple is returning manzana verde. Maybe we need to update generateB to use the West Coast locale? I am using it right now and it appears to be working.

dean1510 commented 8 years ago

@saroyama ensure you're calling TK exactly on "green apple". I've changed "+" in your URL to "%20" but it also returns error.

saroyama commented 8 years ago

@dean1510 System.out.println(generateURL("en", "es", "green apple")); return this url: http://translate.google.com/translate_a/single?client=t&hl=en&sl=en&tl=es&text=green+apple&multires=1&otf=0&pc=0&trs=1&ssel=0&tsel=0&sc=1&dt=t&ie=UTF-8&oe=UTF-8&tk=514818.127961 and it return 403 error

saroyama commented 8 years ago

@dean1510 Sorry, i get new class, now all works