Add time markers to synthesizeToFile API.

Also rename onUtteranceRangeStart to onRangeStart based on feedback from
the API council.

Bug: 35767714
Bug: 35767290
Test: cts-tradefed run cts-dev --module CtsSpeechTestCases
Change-Id: I2c17a06e401313d4f35e5ec4958c2251c195ef05
This commit is contained in:
Niels Egberts
2017-03-21 15:29:24 +00:00
parent 10df3fe76f
commit 5d0ea0fe21
11 changed files with 27 additions and 18 deletions

View File

@@ -37797,9 +37797,9 @@ package android.speech.tts {
method public abstract void onDone(java.lang.String);
method public abstract deprecated void onError(java.lang.String);
method public void onError(java.lang.String, int);
method public void onRangeStart(java.lang.String, int, int, int);
method public abstract void onStart(java.lang.String);
method public void onStop(java.lang.String, boolean);
method public void onUtteranceRangeStart(java.lang.String, int, int);
}
public class Voice implements android.os.Parcelable {

View File

@@ -40939,9 +40939,9 @@ package android.speech.tts {
method public abstract void onDone(java.lang.String);
method public abstract deprecated void onError(java.lang.String);
method public void onError(java.lang.String, int);
method public void onRangeStart(java.lang.String, int, int, int);
method public abstract void onStart(java.lang.String);
method public void onStop(java.lang.String, boolean);
method public void onUtteranceRangeStart(java.lang.String, int, int);
}
public class Voice implements android.os.Parcelable {

View File

@@ -37988,9 +37988,9 @@ package android.speech.tts {
method public abstract void onDone(java.lang.String);
method public abstract deprecated void onError(java.lang.String);
method public void onError(java.lang.String, int);
method public void onRangeStart(java.lang.String, int, int, int);
method public abstract void onStart(java.lang.String);
method public void onStop(java.lang.String, boolean);
method public void onUtteranceRangeStart(java.lang.String, int, int);
}
public class Voice implements android.os.Parcelable {

View File

@@ -309,4 +309,9 @@ class FileSynthesisCallback extends AbstractSynthesisCallback {
return header;
}
@Override
public void rangeStart(int markerInFrames, int start, int end) {
mDispatcher.dispatchOnRangeStart(markerInFrames, start, end);
}
}

View File

@@ -96,6 +96,8 @@ oneway interface ITextToSpeechCallback {
* @param utteranceId Unique id identifying the synthesis request.
* @param start The start character index of the range in the utterance text.
* @param end The end character index of the range (exclusive) in the utterance text.
* @param frame The start position in frames in the audio of the request where this range is
* spoken.
*/
void onUtteranceRangeStart(String utteranceId, int start, int end);
void onRangeStart(String utteranceId, int start, int end, int frame);
}

View File

@@ -272,6 +272,7 @@ class PlaybackSynthesisCallback extends AbstractSynthesisCallback {
}
}
@Override
public void rangeStart(int markerInFrames, int start, int end) {
if (mItem == null) {
Log.e(TAG, "mItem is null");

View File

@@ -148,8 +148,8 @@ public interface SynthesisCallback {
*
* <p>Calling this method means that at the given audio frame, the given range of the input is
* about to be spoken. If this method is called the client will receive a callback on the
* listener ({@link UtteranceProgressListener#onUtteranceRangeStart}) at the moment that frame
* has been reached by the playback head.
* listener ({@link UtteranceProgressListener#onRangeStart}) at the moment that frame has been
* reached by the playback head.
*
* <p>The markerInFrames is a frame index into the audio for this synthesis request, i.e. into
* the concatenation of the audio bytes sent to audioAvailable for this synthesis request. The

View File

@@ -224,7 +224,7 @@ final class SynthesisPlaybackQueueItem extends PlaybackQueueItem
return;
}
// Inform the client.
getDispatcher().dispatchOnUtteranceRangeStart(marker.start, marker.end);
getDispatcher().dispatchOnRangeStart(marker.start, marker.end, marker.frames);
// Listen for the next marker.
// It's ok if this marker is in the past, in that case onMarkerReached will be called again.
updateMarker();

View File

@@ -2159,10 +2159,10 @@ public class TextToSpeech {
}
@Override
public void onUtteranceRangeStart(String utteranceId, int start, int end) {
public void onRangeStart(String utteranceId, int start, int end, int frame) {
UtteranceProgressListener listener = mUtteranceProgressListener;
if (listener != null) {
listener.onUtteranceRangeStart(utteranceId, start, end);
listener.onRangeStart(utteranceId, start, end, frame);
}
}
};

View File

@@ -668,7 +668,7 @@ public abstract class TextToSpeechService extends Service {
void dispatchOnAudioAvailable(byte[] audio);
public void dispatchOnUtteranceRangeStart(int start, int end);
public void dispatchOnRangeStart(int start, int end, int frame);
}
/** Set of parameters affecting audio output. */
@@ -889,11 +889,11 @@ public abstract class TextToSpeechService extends Service {
}
@Override
public void dispatchOnUtteranceRangeStart(int start, int end) {
public void dispatchOnRangeStart(int start, int end, int frame) {
final String utteranceId = getUtteranceId();
if (utteranceId != null) {
mCallbacks.dispatchOnUtteranceRangeStart(
getCallerIdentity(), utteranceId, start, end);
mCallbacks.dispatchOnRangeStart(
getCallerIdentity(), utteranceId, start, end, frame);
}
}
@@ -1574,14 +1574,14 @@ public abstract class TextToSpeechService extends Service {
}
}
public void dispatchOnUtteranceRangeStart(
Object callerIdentity, String utteranceId, int start, int end) {
public void dispatchOnRangeStart(
Object callerIdentity, String utteranceId, int start, int end, int frame) {
ITextToSpeechCallback cb = getCallbackFor(callerIdentity);
if (cb == null) return;
try {
cb.onUtteranceRangeStart(utteranceId, start, end);
cb.onRangeStart(utteranceId, start, end, frame);
} catch (RemoteException e) {
Log.e(TAG, "Callback dispatchOnUtteranceRangeStart(String, int, int) failed: " + e);
Log.e(TAG, "Callback dispatchOnRangeStart(String, int, int, int) failed: " + e);
}
}

View File

@@ -135,8 +135,9 @@ public abstract class UtteranceProgressListener {
* @param utteranceId Unique id identifying the synthesis request.
* @param start The start index of the range in the utterance text.
* @param end The end index of the range (exclusive) in the utterance text.
* @param frame The position in frames in the audio of the request where this range is spoken.
*/
public void onUtteranceRangeStart(String utteranceId, int start, int end) {}
public void onRangeStart(String utteranceId, int start, int end, int frame) {}
/**
* Wraps an old deprecated OnUtteranceCompletedListener with a shiny new progress listener.