I am using android.speech.tts.TextToSpeech and would like to have an UtteranceProgressListener that does not override the deprecated one rror but rather uses the recommended one rror instead. Does anyone know how to do that? I want to avoid using a deprecated API in my app.
Building using Android Studio and without overriding the deprecated one rror tells me that my Fragment "is not abstract and does not override abstract method one rror(String) in UtteranceProgressListener". My current solution looks like this:
private final UtteranceProgressListener utteranceProgressListener = new UtteranceProgressListener() {
/**
* Called when an utterance "starts" as perceived by the caller. This will
* be soon before audio is played back in the case of a {@link TextToSpeech#speak}
* or before the first bytes of a file are written to the file system in the case
* of {@link TextToSpeech#synthesizeToFile}.
*
* @param utteranceId The utterance ID of the utterance.
*/
@Override
public void onStart(String utteranceId) {
}
/**
* Called when an utterance has successfully completed processing.
* All audio will have been played back by this point for audible output, and all
* output will have been written to disk for file synthesis requests.
* <p>
* This request is guaranteed to be called after {@link #onStart(String)}.
*
* @param utteranceId The utterance ID of the utterance.
*/
@Override
public void onDone(String utteranceId) {
}
/**
* Called when an error has occurred during processing. This can be called
* at any point in the synthesis process. Note that there might be calls
* to {@link #onStart(String)} for specified utteranceId but there will never
* be a call to both {@link #onDone(String)} and {@link #onError(String)} for
* the same utterance.
*
* @param utteranceId The utterance ID of the utterance.
* @deprecated Use {@link #onError(String, int)} instead
*/
@Override
public void one rror(String utteranceId) {
}
@Override
public void one rror(String utteranceId, final int errorCode) {
}
};
I looked here but was unable to see an improvement to my current solution.
CodePudding user response:
You can't- it's deprecated, but not removed. That means it needs to be defined. You can define it to do nothing, or to call one rror(String, int) with a faked error code. But you can't not define it. It won't compile without it.