2011-01-27 8 views
25

Viene segnalato che, in alcuni (non tutti) HTC Desire HD (FRF91, 2.2) e HTC EVO 4G (PC36100 | 3.29.651.5, 2.2), il TextToSpeech.OnInitListener.onInit(int) viene chiamato ripetutamente (oltre 1500 volte nello spazio di pochi secondi) sullo stesso oggetto. Questo comportamento non si verifica per nessuno dei miei altri utenti (o con altri utenti di Desire HD) AFAICT.TextToSpeech.OnInitListener.onInit (int) viene chiamato continuamente

Il codice è:

TextToSpeech tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() { 
    private int mCallCount = 0; // trying to investigate potential infinite loops 

    @Override 
    public void onInit(int status) { 
     if ((mCallCount % 100) == 1) { 
      // report this 
     } 
     mCallCount++; 
    } 
}); 

Chiunque tutte le idee?

EDIT: Ho anche provato a chiamare il metodo shutdown() (la prima volta che vengono rilevate più chiamate listener), ma questo non sembra essere d'aiuto.

+0

elaborato per favore !! che cos'è lo stato ?? quando viene aggiornato? – garima

+0

Lo stato è SUCCESSO (AFAICT). Questo è il massimo che posso decifrare dai rapporti Flurry. Succede solo a circa 1 su 1000 utenti, ma per quegli utenti succede, succede sempre. –

+0

Dov'è il codice che abilita il servizio TTS? Che altro stai facendo all'interno di 'onInit()' che stai lasciando fuori? È possibile che qualcosa si riattivi. Inoltre, hai provato tutto se non sono installate risorse TTS? I tuoi utenti 1-in-1000 potrebbero essere quelli con esso non caricati. Il servizio TTS verrà ancora inizializzato (è comunque possibile riprodurre i earcons ma non i speech). –

risposta

1

Forse si dovrebbe andare in giro con il proprio metodo di intermediario, per esempio:

private long lastCall = 0; 
private long deepBreath = 5*1000; //5 seconds 
private boolean hasRested; 

TextToSpeech tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() { 
    @Override 
    public void onInit(int status) { 
     long thisCall = Calendar.getInstance().getTimeInMillis(); 
     intermediaryMethod(status, thisCall); 
    } 
}); 

//new method 
public void intermediaryMethod(int status, long thisCall) { 
    hasRested = (thisCall-lastCall)>=deepBreath; 
    if (hasRested) { 
     lastCall = thisCall; 
     //do something about 'status' 
    } 
} 
1

Questo può o non può aiutare, ma ho avuto un problema simile quando TTS chiamata da un servizio, per mia fortuna ho era meglio fare i miei compiti da un'attività che risolveva il problema.

Se si esegue questa operazione, ed è opportuno, assicurarsi che il proprio manifesto per l'attività ha:

android:finishOnTaskLaunch="true" 
0

Tentare di creare oggetto della Textospeech prima su creare cioè. globalmente. Gestisci questo codice e verifica se chiama ancora molte volte ????

public class TtsActivity extends Activity implements OnInitListener { 

private int MY_DATA_CHECK_CODE = 0; 

private TextToSpeech tts; 

private EditText inputText; 
private Button speakButton; 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    inputText = (EditText) findViewById(R.id.input_text); 
    speakButton = (Button) findViewById(R.id.speak_button); 

    speakButton.setOnClickListener(new OnClickListener() {   
     @Override 
     public void onClick(View v) { 
      String text = inputText.getText().toString(); 
      if (text!=null && text.length()>0) { 
       Toast.makeText(TtsActivity.this, "Saying: " + text, Toast.LENGTH_LONG).show(); 
       tts.speak(text, TextToSpeech.QUEUE_ADD, null); 
      } 
     } 
    }); 

    Intent checkIntent = new Intent(); 
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); 
    startActivityForResult(checkIntent, MY_DATA_CHECK_CODE); 

} 

protected 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 
      tts = new TextToSpeech(this, this); 
     } 
     else { 
      // missing data, install it 
      Intent installIntent = new Intent(); 
      installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); 
      startActivity(installIntent); 
     } 
    } 

} 

@Override 
public void onInit(int status) {   
    if (status == TextToSpeech.SUCCESS) { 
     Toast.makeText(TtsActivity.this, 
       "Text-To-Speech engine is initialized", Toast.LENGTH_LONG).show(); 
    } 
    else if (status == TextToSpeech.ERROR) { 
     Toast.makeText(TtsActivity.this, 
       "Error occurred while initializing Text-To-Speech engine", Toast.LENGTH_LONG).show(); 
    } 
} 

}