Translation app Text to Speech - Android

Asked

Viewed 651 times

1

Hello, I’m beginner on android and would like to make a simple translator, where the user write anything and click the button with the desired language to translate aloud, how would be the translation algorithm for other languages ? Just follow my code

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout);

        edt_texto =(EditText)findViewById(R.id.edt_texto);
        btn =(Button)findViewById(R.id.btn);

        t2s = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {

                t2s.setLanguage(Locale.getDefault());

            }
        });

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String fala = edt_texto.getText().toString();

                t2s.speak(fala,TextToSpeech.QUEUE_FLUSH,null);
            }
        });
    }
  • Texttospeech does not translate. It just makes the synthesized speech of the text.

1 answer

2

You are already using other languages.

When using:

t2s.setLanguage(Locale.getDefault());

Using the selected language on the device.

You can, however, define a different language with:

t2s.setLanguage( new Locale("en", "US"));

or

t2s.setLanguage( Locale.JAPAN );

or:

t2s.setLanguage( Locale.forLanguageTag("en-US") );
  • Texttospeech does not translate. It just makes the synthesized speech of the text.

  • I’m sorry, I didn’t understand. I was also looking for a translation library for java but unfortunately I didn’t find any. The only alternative will be a translation API, but the user will have to be online to use it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.