I am making an android app for language translation in real time...I used recognizer intent to get voice input from user after which it gives me a list of options of what the user spoke.Now I want to translate it another language using google translate api but I don't know how to use it. Code for what I have done till now is.Also if you can tell me how it can be done that instead of giving me options of what I spoke , it selects one on its own and then use google translate api on that....
package com.example.testing; import java.util.ArrayList; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.speech.RecognizerIntent; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; public class Voice extends Activity implements OnClickListener{ ListView lv; static final int check=1111; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.voice); lv=(ListView)findViewById(R.id.lvVoiceReturn); Button b=(Button)findViewById(R.id.bVoice); b.setOnClickListener(this); } @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent i=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak Up"); startActivityForResult(i, check); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub if(requestCode == check && resultCode==RESULT_OK){ ArrayList<String> results=data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results)); } super.onActivityResult(requestCode, resultCode, data); } }
The Google Translate API is not free. Its pricing is based off monthly usage in terms of millions of characters. It costs $20 per 1 million characters for translation or language detection. Price is per character sent to the API for processing, including whitespace characters.
You can use google script which has FREE translate API. All you need is a common google account and do these THREE EASY STEPS. 2) Click Publish -> Deploy as webapp -> Who has access to the app: Anyone even anonymous -> Deploy. And then copy your web app url, you will need it for calling translate API.
Here is the documentation for https://developers.google.com/translate/
Also, refer to this demo project on the same
Bing also provides a translation API
Check this Google translation API example .
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With