TextToSpeech Android build version does not play audio

I have strange behavior of my text-to-speech mechanism on Android:

When I check the text for speech on my Galaxy S5, everything is fine, the sound plays in Turkish and German.

On some other phones (for example, LG), the ToSpeech text also works, except for the following case:

  • Export the application (build apk) and install it manually on the phone
  • Switch to Turkish (German always works!)

The problem is that I am not getting an error message - it seems that the TTS is initializing normally.

Any clue would be greatly appreciated!

here is my code:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getActionBar().setLogo(R.drawable.anne_eli_icons_pfeile_zurueck_weiss_17px);
        getActionBar().setHomeButtonEnabled(true);
        textToSpeech = new TextToSpeech(this, this);
    }

    @Override
    public void onInit(int status) {
        if (status == TextToSpeech.SUCCESS) {
            log("onInit()");
            int result = textToSpeech.setLanguage(new Locale(getTransLanguage()));
            log("result:" + result);
            textToSpeech.setSpeechRate(1.2f); // set speech speed rate

            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                Tools.showToast(this, "Language " + getTransLanguage() + " is not supported! Error code: " + result);
                Intent installIntent = new Intent();
                installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                startActivity(installIntent);

            } else {
                speechEnabled = true;
            }

        } else {
            speechEnabled = false;
            Tools.showToast(this, "Text to speech initialization failed!");
        }
    }
+4
source share
1 answer

, , TTS:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;

/**
 * This class demonstrates checking for a TTS engine, and if one is
 * available it will spit out some speak.
*/
public class Main extends Activity implements TextToSpeech.OnInitListener
{
private TextToSpeech mTts;
// This code can be any value you want, its just a checksum.
private static final int MY_DATA_CHECK_CODE = 1234;

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Fire off an intent to check if a TTS engine is installed
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);

}

/**
 * Executed when a new TTS is instantiated. Some static text is spoken via TTS here.
 * @param i
 */
public void onInit(int i)
{
    mTts.speak("Hello folks, welcome to my little demo on Text To Speech.",
            TextToSpeech.QUEUE_FLUSH,  // Drop all pending entries in the playback queue.
            null);
}


/**
 * This is the callback from the TTS engine check, if a TTS is installed we
 * create a new TTS instance (which in turn calls onInit), if not then we will
 * create an intent to go off and install a TTS engine
 * @param requestCode int Request code returned from the check for TTS engine.
 * @param resultCode int Result code returned from the check for TTS engine.
 * @param data Intent Intent returned from the TTS check.
 */
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == MY_DATA_CHECK_CODE)
    {
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS)
        {
            // success, create the TTS instance
            mTts = new TextToSpeech(this, this);
        }
        else
        {
            // missing data, install it
            Intent installIntent = new Intent();
            installIntent.setAction(
                    TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);
        }
    }
}

/**
 * Be kind, once you've finished with the TTS engine, shut it down so other
 * applications can use it without us interfering with it :)
 */
@Override
public void onDestroy()
{
    // Don't forget to shutdown!
    if (mTts != null)
    {
        mTts.stop();
        mTts.shutdown();
    }
    super.onDestroy();
}

}

0

All Articles