Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65c50784 authored by Niels Egberts's avatar Niels Egberts
Browse files

Implement time markers for TTS.

The service can inform the framework at which frame a part of the input
is spoken, and that information is then relayed to the client.

This can be used to highlight the currently spoken word/sentence or to
resume synthesis requests at the start of the last word/sentence.

Test: manual
Change-Id: Ie20a6764a8788cc3539cb058425e55eb6fde07db
parent 1a292884
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -36245,6 +36245,7 @@ package android.speech.tts {
    method public abstract int getMaxBufferSize();
    method public abstract boolean hasFinished();
    method public abstract boolean hasStarted();
    method public default void rangeStart(int, int, int);
    method public abstract int start(int, int, int);
  }
@@ -36397,6 +36398,7 @@ package android.speech.tts {
    method public void onError(java.lang.String, 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 {
+2 −0
Original line number Diff line number Diff line
@@ -39235,6 +39235,7 @@ package android.speech.tts {
    method public abstract int getMaxBufferSize();
    method public abstract boolean hasFinished();
    method public abstract boolean hasStarted();
    method public default void rangeStart(int, int, int);
    method public abstract int start(int, int, int);
  }
@@ -39387,6 +39388,7 @@ package android.speech.tts {
    method public void onError(java.lang.String, 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 {
+2 −0
Original line number Diff line number Diff line
@@ -36366,6 +36366,7 @@ package android.speech.tts {
    method public abstract int getMaxBufferSize();
    method public abstract boolean hasFinished();
    method public abstract boolean hasStarted();
    method public default void rangeStart(int, int, int);
    method public abstract int start(int, int, int);
  }
@@ -36518,6 +36519,7 @@ package android.speech.tts {
    method public void onError(java.lang.String, 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 {
+22 −1
Original line number Diff line number Diff line
@@ -340,4 +340,25 @@ class BlockingAudioTrack {
        return value < min ? min : (value < max ? value : max);
    }

    /**
     * @see
     *     AudioTrack#setPlaybackPositionUpdateListener(AudioTrack.OnPlaybackPositionUpdateListener).
     */
    public void setPlaybackPositionUpdateListener(
            AudioTrack.OnPlaybackPositionUpdateListener listener) {
        synchronized (mAudioTrackLock) {
            if (mAudioTrack != null) {
                mAudioTrack.setPlaybackPositionUpdateListener(listener);
            }
        }
    }

    /** @see AudioTrack#setNotificationMarkerPosition(int). */
    public void setNotificationMarkerPosition(int frames) {
        synchronized (mAudioTrackLock) {
            if (mAudioTrack != null) {
                mAudioTrack.setNotificationMarkerPosition(frames);
            }
        }
    }
}
+15 −0
Original line number Diff line number Diff line
@@ -83,4 +83,19 @@ oneway interface ITextToSpeechCallback {
     * callback.
     */
    void onAudioAvailable(String utteranceId, in byte[] audio);

    /**
     * Tells the client that the engine is about to speak the specified range of the utterance.
     *
     * <p>
     * Only called if the engine supplies timing information by calling
     * {@link SynthesisCallback#rangeStart(int, int, int)} and only when the request is played back
     * by the service, not when using {@link android.speech.tts.TextToSpeech#synthesizeToFile}.
     * </p>
     *
     * @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.
     */
    void onUtteranceRangeStart(String utteranceId, int start, int end);
}
Loading