V
V
Vanes Ri_Lax2017-08-04 10:04:24
Android
Vanes Ri_Lax, 2017-08-04 10:04:24

Why does TextToSpeech throw an error?

Good afternoon, I
wrote a simple code for sound synthesis, I took an example here
Here is my actual code:

public class MainActivity extends AppCompatActivity implements TextToSpeech.OnInitListener{

    private Button btn;
    private TextToSpeech mTTS;


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


        btn = (Button)findViewById(R.id.button);
        mTTS = new TextToSpeech(this, this);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String text = "А Васька слушает да ест";
                mTTS.speak(text, TextToSpeech.QUEUE_FLUSH, null);
            }
        });

    }


    @Override
    public void onInit(int status) {
        if (status == TextToSpeech.SUCCESS) {

            Locale locale = new Locale("ru");

            int result = mTTS.setLanguage(locale);
            //int result = mTTS.setLanguage(Locale.getDefault());

            if (result == TextToSpeech.LANG_MISSING_DATA
                    || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                Log.e("TTS", "Извините, этот язык не поддерживается");
            } else {

            }

        } else {
            Log.e("TTS", "Ошибка!");
        }
    }
    @Override
    public void onDestroy() {
        // Don't forget to shutdown mTTS!
        if (mTTS != null) {
            mTTS.stop();
            mTTS.shutdown();
        }
        super.onDestroy();
    }
}

In the log writes:
08-04 06:58:50.716 10158-10158/? E/TTS: Извините, этот язык не поддерживается

And when the button is clicked, it displays:
08-04 06:58:55.056 3176-10171/com.svox.pico E/CompatTtsService: setLanguage(rus,RUS,) failed

I run the application on the SDK

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aol-nnov, 2017-08-04
@aol-nnov

// Если этот код работает, его написал Александр Климов,
// а если нет, то не знаю, кто его писал.

And if he wrote it himself, then TextToSpeech.LANG_MISSING_DATA should lead you to a certain thought!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question