使用TTS

时间:2016-01-11 19:44:48

标签: android stack-overflow logcat

对于我的平板电脑,我的应用在使用TTS时不断崩溃。这是logcat:

E / AndroidRuntime(4286):java.lang.StackOverflowError E / AndroidRuntime(4286):at java.util.HashMap.containsKey(HashMap.java:327) E / AndroidRuntime(4286):at java.util.HashSet.contains(HashSet.java:138) E / AndroidRuntime(4286):在android.provider.Settings $ Secure.getStringForUser(Settings.java:2757) E / AndroidRuntime(4286):在android.provider.Settings $ Secure.getString(Settings.java:2751) E / AndroidRuntime(4286):在android.speech.tts.TtsEngines.getDefaultEngine(TtsEngines.java:75) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.getDefaultEngine(TextToSpeech.java:1235) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:595) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:553) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:527) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:512) E / AndroidRuntime(4286):at com.fa.daily.activity.AddGoogleNewsActivity.onInit(AddGoogleNewsActivity.java:275) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.dispatchOnInit(TextToSpeech.java:640) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:619) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:553) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:527) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:512) E / AndroidRuntime(4286):at com.fa.daily.activity.AddGoogleNewsActivity.onInit(AddGoogleNewsActivity.java:275) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.dispatchOnInit(TextToSpeech.java:640) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:619) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:553) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:527) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:512) E / AndroidRuntime(4286):at com.fa.daily.activity.AddGoogleNewsActivity.onInit(AddGoogleNewsActivity.java:275) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.dispatchOnInit(TextToSpeech.java:640) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:619) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:553) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:527) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:512) E / AndroidRuntime(4286):at com.fa.daily.activity.AddGoogleNewsActivity.onInit(AddGoogleNewsActivity.java:275) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.dispatchOnInit(TextToSpeech.java:640) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:619) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:553) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:527) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:512) E / AndroidRuntime(4286):at com.fa.daily.activity.AddGoogleNewsActivity.onInit(AddGoogleNewsActivity.java:275) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.dispatchOnInit(TextToSpeech.java:640) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:619) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:553) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:527) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:512) E / AndroidRuntime(4286):at com.fa.daily.activity.AddGoogleNewsActivity.onInit(AddGoogleNewsActivity.java:275) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.dispatchOnInit(TextToSpeech.java:640) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:619) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:553) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:527) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:512) E / AndroidRuntime(4286):at com.fa.daily.activity.AddGoogleNewsActivity.onInit(AddGoogleNewsActivity.java:275) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.dispatchOnInit(TextToSpeech.java:640) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:619) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:553) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:527) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:512) E / AndroidRuntime(4286):at com.fa.daily.activity.AddGoogleNewsActivity.onInit(AddGoogleNewsActivity.java:275) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.dispatchOnInit(TextToSpeech.java:640) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:619) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:553) E / AndroidRuntime(4286):在android.speech.tts.TextToSpeech。(TextToSpeech.java:527) E / AndroidRuntime(4286):在android

这是我的代码:

    public class AddGoogleNewsActivity extends BaseActivity implements TextToSpeech.OnInitListener {

private Tracker mTracker;
private TextToSpeech mTts;

private static final String BASE64_PUBLIC_KEY = "abc";

// Generate your own 20 random bytes, and put them here.
private static final byte[] SALT = new byte[] {
        abc
};

private LicenseCheckerCallback mLicenseCheckerCallback;
private LicenseChecker mChecker;
// A handler on the UI thread.
private Handler mHandler;

private String intent;

private static final int[] TOPIC_NAME = new int[]{R.string.google_news_top_stories, R.string.google_news_world, R.string.google_news_business,
        R.string.google_news_technology, R.string.google_news_entertainment, R.string.google_news_sports, R.string.google_news_science, R.string.google_news_health};

private static final String[] TOPIC_CODES = new String[]{null, "w", "b", "t", "e", "s", "snc", "m"};

private static final int[] CB_IDS = new int[]{R.id.cb_top_stories, R.id.cb_world, R.id.cb_business, R.id.cb_technology, R.id.cb_entertainment,
        R.id.cb_sports, R.id.cb_science, R.id.cb_health};

@Override
protected void onCreate(Bundle savedInstanceState) {
    UiUtils.setPreferenceTheme(this);
    super.onCreate(savedInstanceState);

    setResult(RESULT_CANCELED);

    /*if (DonateActivity.checkForDonation(this) == true){
    } else {
        Toast.makeText(AddGoogleNewsActivity.this, "Not bought legally", Toast.LENGTH_SHORT).show();
        finish();
    }*/

    setContentView(R.layout.activity_add_google_news);

    mHandler = new Handler();

    // Try to use more data here. ANDROID_ID is a single point of attack.
    String deviceId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);

    // Library calls this when it's done.
    mLicenseCheckerCallback = new FALicenseCheckerCallback();
    // Construct the LicenseChecker with a policy.
    mChecker = new LicenseChecker(
            this, new ServerManagedPolicy(this,
            new AESObfuscator(SALT, getPackageName(), deviceId)),
            BASE64_PUBLIC_KEY);
    checkLicense(mChecker, mLicenseCheckerCallback);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    UiUtils.setPreferenceToolbar(this, toolbar);

    intent = (String) getIntent().getSerializableExtra("intent");

    if (PrefUtils.getBoolean(PrefUtils.GOOGLE_REPEAT, true)) {
        mTts = new TextToSpeech(this, this);
        mTts.speak(getString(R.string.google_news_welcome),
                TextToSpeech.QUEUE_FLUSH,  // Drop all pending entries in the playback queue.
                null);
        SnackbarManager.show(
                Snackbar.with(getApplicationContext()) // context
                        .type(SnackbarType.MULTI_LINE)
                        .duration(Snackbar.SnackbarDuration.LENGTH_LONG)
                        .color(getResources().getColor(R.color.light_accent_color)) // change the background color
                        .actionColor(Color.WHITE)
                        .text(getString(R.string.repeat_google_audio)) // text to display
                        .actionLabel("OK") // action button label
                        .actionListener(new ActionClickListener() {
                            @Override
                            public void onActionClicked(Snackbar snackbar) {
                                PrefUtils.putBoolean(PrefUtils.GOOGLE_REPEAT, false);
                            }
                        }) // action button's ActionClickListener
                , this);
    }

    final TextView okButton = (TextView) findViewById(R.id.button_ok);
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            onClickOk(v);
        }
    });
    final TextView cancelButton = (TextView) findViewById(R.id.button_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            onClickCancel(v);
        }
    });

    LandingTechnique(findViewById(R.id.welcome_text));
    LandingTechnique(findViewById(R.id.button_cancel));
    LandingTechnique(findViewById(R.id.button_ok));
    StandUpTechnique(findViewById(R.id.text_top_stories));
    StandUpTechnique(findViewById(R.id.text_world));
    StandUpTechnique(findViewById(R.id.text_entertainment));
    StandUpTechnique(findViewById(R.id.text_sports));
    StandUpTechnique(findViewById(R.id.text_science));
    StandUpTechnique(findViewById(R.id.text_business));
    StandUpTechnique(findViewById(R.id.text_technology));
    StandUpTechnique(findViewById(R.id.text_health));

    final ImageView TopStoriesLayout = (ImageView) findViewById(R.id.image_top_stories);
    final ImageView WorldLayout = (ImageView) findViewById(R.id.image_world);
    final ImageView EntertainmentLayout = (ImageView) findViewById(R.id.image_entertainment);
    final ImageView SportsLayout = (ImageView) findViewById(R.id.image_sports);
    final ImageView ScienceLayout = (ImageView) findViewById(R.id.image_science);
    final ImageView BusinessLayout = (ImageView) findViewById(R.id.image_business);
    final ImageView TechnologyLayout = (ImageView) findViewById(R.id.image_technology);
    final ImageView HealthLayout = (ImageView) findViewById(R.id.image_health);

    Picasso.with(getBaseContext()).load("http://i.imgur.com/EZE7Lce.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).fetch();
    Picasso.with(getBaseContext()).load("http://i.imgur.com/1YCDUZl.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).fetch();
    Picasso.with(getBaseContext()).load("http://i.imgur.com/37v15CR.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).fetch();
    Picasso.with(getBaseContext()).load("http://i.imgur.com/ARfrQfC.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).fetch();
    Picasso.with(getBaseContext()).load("http://i.imgur.com/9Z6BeFt.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).fetch();
    Picasso.with(getBaseContext()).load("http://i.imgur.com/RInLzZo.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).fetch();
    Picasso.with(getBaseContext()).load("http://i.imgur.com/HlH2LOa.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).fetch();
    Picasso.with(getBaseContext()).load("http://i.imgur.com/UjJzRl6.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).fetch();

    Picasso.with(getBaseContext()).load("http://i.imgur.com/EZE7Lce.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).into(TopStoriesLayout);
    Picasso.with(getBaseContext()).load("http://i.imgur.com/1YCDUZl.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).into(WorldLayout);
    Picasso.with(getBaseContext()).load("http://i.imgur.com/37v15CR.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).into(EntertainmentLayout);
    Picasso.with(getBaseContext()).load("http://i.imgur.com/ARfrQfC.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).into(SportsLayout);
    Picasso.with(getBaseContext()).load("http://i.imgur.com/9Z6BeFt.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).into(ScienceLayout);
    Picasso.with(getBaseContext()).load("http://i.imgur.com/RInLzZo.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).into(BusinessLayout);
    Picasso.with(getBaseContext()).load("http://i.imgur.com/HlH2LOa.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).into(TechnologyLayout);
    Picasso.with(getBaseContext()).load("http://i.imgur.com/UjJzRl6.jpg").transform(new GrayTransformation(Picasso.with(getBaseContext()))).into(HealthLayout);

    MainApplication application = (MainApplication) getApplication();
    mTracker = application.getDefaultTracker();
}
private YoYo.YoYoString rope;

@Override
protected void onResume() {
    super.onResume();
    mTracker.setScreenName("Choose topics");
    mTracker.send(new HitBuilders.ScreenViewBuilder().build());
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        finish();
        if((intent != null) && intent.equals("reveal")){
            overridePendingTransition(R.anim.close_feed, R.anim.open_add);
        }
        return true;
    }

    return false;
}

public void onClickOk(View view) {

    int topicbase = 0;
    if (((CheckBox) findViewById(CB_IDS[topicbase])).isChecked()) {
        for (int topic = 0; topic < TOPIC_NAME.length; topic++) {
            if (((CheckBox) findViewById(CB_IDS[topic])).isChecked()) {
                String url = "http://news.google.com/news?hl=" + Locale.getDefault().getLanguage() + "&output=rss";
                if (TOPIC_CODES[topic] != null) {
                    url += "&topic=" + TOPIC_CODES[topic];
                }
                FeedDataContentProvider.addFeed(this, url, getString(TOPIC_NAME[topic]), true);
            }
        }
        setResult(RESULT_OK);
        Intent goToBoot = new Intent(this, BootActivity.class);
        goToBoot.putExtra("intent", "complete");
        startActivity(goToBoot);

        if (PrefUtils.getBoolean(PrefUtils.FIRST_OPEN, true)) {
            PrefUtils.putBoolean(PrefUtils.FIRST_OPEN, false);
        }
    } else {
        SnackbarManager.show(
                Snackbar.with(getApplicationContext()) // context
                        .type(SnackbarType.MULTI_LINE)
                        .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
                        .color(getResources().getColor(R.color.light_accent_color)) // change the background color
                        .actionColor(Color.WHITE)
                        .text(getString(R.string.google_news_add)) // text to display
                        .actionLabel("OK") // action button label
                        .actionListener(new ActionClickListener() {
                            @Override
                            public void onActionClicked(Snackbar snackbar) {
                                PrefUtils.putBoolean(PrefUtils.FIRST_START, false);
                            }
                        }) // action button's ActionClickListener
                , this);
    }
}

public void onClickCancel(View view) {
    finish();
    if((intent != null) && intent.equals("reveal")){
        overridePendingTransition(R.anim.close_feed, R.anim.open_add);
    }
}

@Override
public void onBackPressed(){
    finish();
    if((intent != null) && intent.equals("reveal")){
        overridePendingTransition(R.anim.close_feed, R.anim.open_add);
    }
}

@Override
public void onInit(int i) {
    mTts = new TextToSpeech(AddGoogleNewsActivity.this, this);
    mTts.speak(getString(R.string.google_news_welcome),
            TextToSpeech.QUEUE_FLUSH,  // Drop all pending entries in the playback queue.
            null);
}

@Override
public void onDestroy() {
    super.onDestroy();
    // Don't forget to shutdown tts!
    if (mTts != null) {
        mTts.stop();
        mTts.shutdown();
    }
    mChecker.onDestroy();
}

public void StandUpTechnique(View view){
    rope = YoYo.with(Techniques.FadeIn)
            .duration(1000)
            .interpolate(new AccelerateDecelerateInterpolator())
            .playOn(view);
}

public void LandingTechnique(View view){
    rope = YoYo.with(Techniques.FadeIn)
            .duration(1000)
            .interpolate(new AccelerateDecelerateInterpolator())
            .playOn(view);
}

protected Dialog onCreateDialog(int id) {
    final boolean bRetry = id == 1;
    return new AlertDialog.Builder(this)
            .setTitle(R.string.unlicensed_dialog_title)
            .setMessage(bRetry ? R.string.unlicensed_dialog_retry_body : R.string.unlicensed_dialog_body)
            .setPositiveButton(bRetry ? R.string.retry_button : R.string.buy_button, new DialogInterface.OnClickListener() {
                boolean mRetry = bRetry;
                public void onClick(DialogInterface dialog, int which) {
                    if ( mRetry ) {
                        checkLicense(mChecker, mLicenseCheckerCallback);
                    } else {
                        Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                "http://market.android.com/details?id=" + getPackageName()));
                        startActivity(marketIntent);
                    }
                }
            })
            .setNegativeButton(R.string.quit_button, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            }).create();
}

private void checkLicense(LicenseChecker licenseChecker, LicenseCheckerCallback licenseCheckerCallback) {
    //Toast.makeText(AddGoogleNewsActivity.this, getResources().getString(R.string.checking_license), Toast.LENGTH_SHORT).show();
    licenseChecker.checkAccess(licenseCheckerCallback);
}

private void displayResult(final String result) {
    mHandler.post(new Runnable() {
        public void run() {
            Toast.makeText(AddGoogleNewsActivity.this, result, Toast.LENGTH_SHORT).show();
            setProgressBarIndeterminateVisibility(false);
        }
    });
}

private void displayDialog(final boolean showRetry) {
    mHandler.post(new Runnable() {
        public void run() {
            setProgressBarIndeterminateVisibility(false);
            showDialog(showRetry ? 1 : 0);
        }
    });
}

private class FALicenseCheckerCallback implements LicenseCheckerCallback {
    public void allow(int policyReason) {
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        // Should allow user access.
        //displayResult(getString(R.string.allow));
    }

    public void dontAllow(int policyReason) {
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        displayResult(getString(R.string.dont_allow));
        // Should not allow access. In most cases, the app should assume
        // the user has access unless it encounters this. If it does,
        // the app should inform the user of their unlicensed ways
        // and then either shut down the app or limit the user to a
        // restricted set of features.
        // In this example, we show a dialog that takes the user to Market.
        // If the reason for the lack of license is that the service is
        // unavailable or there is another problem, we display a
        // retry button on the dialog and a different message.
        finish();
        //displayDialog(policyReason == Policy.RETRY);
    }

    public void applicationError(int errorCode) {
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        // This is a polite way of saying the developer made a mistake
        // while setting up or calling the license checker library.
        // Please examine the error code and fix the error.
        String result = String.format(getString(R.string.application_error), errorCode);
        displayResult(result);
    }
}

}

有什么可以解决这个问题的想法吗?

谢谢!

0 个答案:

没有答案