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

Commit b956f37e authored by Narayan Kamath's avatar Narayan Kamath
Browse files

Pass synthesis request params through to the TTS service.

Change-Id: I1ffd617d8dfa0814382643e3cf6b3ab7417c742a
parent 9d31154d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -17137,7 +17137,7 @@ package android.speech {
package android.speech.tts {
  public abstract class SynthesisRequest {
    ctor public SynthesisRequest(java.lang.String);
    ctor public SynthesisRequest(java.lang.String, android.os.Bundle);
    method public abstract int audioAvailable(byte[], int, int);
    method public abstract int completeAudioAvailable(int, int, int, byte[], int, int);
    method public abstract int done();
@@ -17145,6 +17145,7 @@ package android.speech.tts {
    method public java.lang.String getCountry();
    method public java.lang.String getLanguage();
    method public abstract int getMaxBufferSize();
    method public android.os.Bundle getParams();
    method public int getPitch();
    method public int getSpeechRate();
    method public java.lang.String getText();
+3 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package android.speech.tts;

import android.media.AudioFormat;
import android.os.Bundle;
import android.util.Log;

import java.io.File;
@@ -47,8 +48,8 @@ class FileSynthesisRequest extends SynthesisRequest {
    private boolean mStopped = false;
    private boolean mDone = false;

    FileSynthesisRequest(String text, File fileName) {
        super(text);
    FileSynthesisRequest(String text, Bundle params, File fileName) {
        super(text, params);
        mFileName = fileName;
    }

+4 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package android.speech.tts;

import android.media.AudioFormat;
import android.media.AudioTrack;
import android.os.Bundle;
import android.util.Log;

/**
@@ -52,8 +53,9 @@ class PlaybackSynthesisRequest extends SynthesisRequest {
    private boolean mStopped = false;
    private boolean mDone = false;

    PlaybackSynthesisRequest(String text, int streamType, float volume, float pan) {
        super(text);
    PlaybackSynthesisRequest(String text, Bundle params,
            int streamType, float volume, float pan) {
        super(text, params);
        mStreamType = streamType;
        mVolume = volume;
        mPan = pan;
+12 −1
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package android.speech.tts;

import android.os.Bundle;

/**
 * A request for speech synthesis given to a TTS engine for processing.
 *
@@ -28,14 +30,16 @@ package android.speech.tts;
public abstract class SynthesisRequest {

    private final String mText;
    private final Bundle mParams;
    private String mLanguage;
    private String mCountry;
    private String mVariant;
    private int mSpeechRate;
    private int mPitch;

    public SynthesisRequest(String text) {
    public SynthesisRequest(String text, Bundle params) {
        mText = text;
        mParams = new Bundle(params);
    }

    /**
@@ -103,6 +107,13 @@ public abstract class SynthesisRequest {
        return mPitch;
    }

    /**
     * Gets the additional params, if any.
     */
    public Bundle getParams() {
        return mParams;
    }

    /**
     * Gets the maximum number of bytes that the TTS engine can pass in a single call of
     * {@link #audioAvailable}. This does not apply to {@link #completeAudioAvailable}.
+33 −2
Original line number Diff line number Diff line
@@ -424,6 +424,7 @@ public class TextToSpeech {
    private final Map<String, Uri> mEarcons;
    private final Map<String, Uri> mUtterances;
    private final Bundle mParams = new Bundle();
    private String mCurrentEngine = null;

    /**
     * The constructor for the TextToSpeech class, using the default TTS engine.
@@ -524,6 +525,7 @@ public class TextToSpeech {
            dispatchOnInit(ERROR);
            return false;
        } else {
            mCurrentEngine = engine;
            return true;
        }
    }
@@ -685,6 +687,10 @@ public class TextToSpeech {
     *            {@link Engine#KEY_PARAM_UTTERANCE_ID},
     *            {@link Engine#KEY_PARAM_VOLUME},
     *            {@link Engine#KEY_PARAM_PAN}.
     *            Engine specific parameters may be passed in but the parameter keys
     *            must be prefixed by the name of the engine they are intended for. For example
     *            the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the
     *            engine named "com.svox.pico" if it is being used.
     *
     * @return {@link #ERROR} or {@link #SUCCESS}.
     */
@@ -714,6 +720,10 @@ public class TextToSpeech {
     *            Supported parameter names:
     *            {@link Engine#KEY_PARAM_STREAM},
     *            {@link Engine#KEY_PARAM_UTTERANCE_ID}.
     *            Engine specific parameters may be passed in but the parameter keys
     *            must be prefixed by the name of the engine they are intended for. For example
     *            the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the
     *            engine named "com.svox.pico" if it is being used.
     *
     * @return {@link #ERROR} or {@link #SUCCESS}.
     */
@@ -741,6 +751,10 @@ public class TextToSpeech {
     * @param params Parameters for the request. Can be null.
     *            Supported parameter names:
     *            {@link Engine#KEY_PARAM_UTTERANCE_ID}.
     *            Engine specific parameters may be passed in but the parameter keys
     *            must be prefixed by the name of the engine they are intended for. For example
     *            the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the
     *            engine named "com.svox.pico" if it is being used.
     *
     * @return {@link #ERROR} or {@link #SUCCESS}.
     */
@@ -922,6 +936,10 @@ public class TextToSpeech {
     * @param params Parameters for the request. Can be null.
     *            Supported parameter names:
     *            {@link Engine#KEY_PARAM_UTTERANCE_ID}.
     *            Engine specific parameters may be passed in but the parameter keys
     *            must be prefixed by the name of the engine they are intended for. For example
     *            the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the
     *            engine named "com.svox.pico" if it is being used.
     * @param filename Absolute file filename to write the generated audio data to.It should be
     *            something like "/sdcard/myappsounds/mysound.wav".
     *
@@ -945,6 +963,19 @@ public class TextToSpeech {
            copyStringParam(bundle, params, Engine.KEY_PARAM_UTTERANCE_ID);
            copyFloatParam(bundle, params, Engine.KEY_PARAM_VOLUME);
            copyFloatParam(bundle, params, Engine.KEY_PARAM_PAN);

            // Copy over all parameters that start with the name of the
            // engine that we are currently connected to. The engine is
            // free to interpret them as it chooses.
            if (!TextUtils.isEmpty(mCurrentEngine)) {
                for (Map.Entry<String, String> entry : params.entrySet()) {
                    final String key = entry.getKey();
                    if (key != null && key.startsWith(mCurrentEngine)) {
                        bundle.putString(key, entry.getValue());
                    }
                }
            }

            return bundle;
        } else {
            return mParams;
Loading