use of android.speech.tts.TextToSpeechService.UtteranceProgressDispatcher in project android_frameworks_base by DirtyUnicorns.
the class SynthesisPlaybackQueueItem method run.
@Override
public void run() {
final UtteranceProgressDispatcher dispatcher = getDispatcher();
dispatcher.dispatchOnStart();
if (!mAudioTrack.init()) {
dispatcher.dispatchOnError(TextToSpeech.ERROR_OUTPUT);
return;
}
try {
byte[] buffer = null;
// OR (c) done() is called in which case it will return null.
while ((buffer = take()) != null) {
mAudioTrack.write(buffer);
mLogger.onAudioDataWritten();
}
} catch (InterruptedException ie) {
if (DBG)
Log.d(TAG, "Interrupted waiting for buffers, cleaning up.");
}
mAudioTrack.waitAndRelease();
if (mStatusCode == TextToSpeech.SUCCESS) {
dispatcher.dispatchOnSuccess();
} else if (mStatusCode == TextToSpeech.STOPPED) {
dispatcher.dispatchOnStop();
} else {
dispatcher.dispatchOnError(mStatusCode);
}
mLogger.onCompleted(mStatusCode);
}
use of android.speech.tts.TextToSpeechService.UtteranceProgressDispatcher in project android_frameworks_base by crdroidandroid.
the class AudioPlaybackQueueItem method run.
@Override
public void run() {
final UtteranceProgressDispatcher dispatcher = getDispatcher();
dispatcher.dispatchOnStart();
int sessionId = mAudioParams.mSessionId;
mPlayer = MediaPlayer.create(mContext, mUri, null, mAudioParams.mAudioAttributes, sessionId > 0 ? sessionId : AudioManager.AUDIO_SESSION_ID_GENERATE);
if (mPlayer == null) {
dispatcher.dispatchOnError(TextToSpeech.ERROR_OUTPUT);
return;
}
try {
mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.w(TAG, "Audio playback error: " + what + ", " + extra);
mDone.open();
return true;
}
});
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mFinished = true;
mDone.open();
}
});
setupVolume(mPlayer, mAudioParams.mVolume, mAudioParams.mPan);
mPlayer.start();
mDone.block();
finish();
} catch (IllegalArgumentException ex) {
Log.w(TAG, "MediaPlayer failed", ex);
mDone.open();
}
if (mFinished) {
dispatcher.dispatchOnSuccess();
} else {
dispatcher.dispatchOnStop();
}
}
Aggregations