Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 1 | package android.speech.tts; |
| 2 | |
| 3 | import android.os.Bundle; |
| 4 | import android.os.Parcel; |
| 5 | import android.os.Parcelable; |
| 6 | import android.speech.tts.TextToSpeechClient.UtteranceId; |
Niels Egberts | a6cc9b8 | 2014-05-14 13:01:29 +0100 | [diff] [blame] | 7 | import android.util.Log; |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 8 | |
| 9 | /** |
| 10 | * Service-side representation of a synthesis request from a V2 API client. Contains: |
| 11 | * <ul> |
Niels Egberts | a6cc9b8 | 2014-05-14 13:01:29 +0100 | [diff] [blame] | 12 | * <li>The markup object to synthesize containing the utterance.</li> |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 13 | * <li>The id of the utterance (String, result of {@link UtteranceId#toUniqueString()}</li> |
Przemyslaw Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 14 | * <li>The synthesis voice name (String, result of {@link VoiceInfo#getName()})</li> |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 15 | * <li>Voice parameters (Bundle of parameters)</li> |
| 16 | * <li>Audio parameters (Bundle of parameters)</li> |
| 17 | * </ul> |
| 18 | */ |
| 19 | public final class SynthesisRequestV2 implements Parcelable { |
Niels Egberts | a6cc9b8 | 2014-05-14 13:01:29 +0100 | [diff] [blame] | 20 | |
| 21 | private static final String TAG = "SynthesisRequestV2"; |
| 22 | |
| 23 | /** Synthesis markup */ |
| 24 | private final Markup mMarkup; |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 25 | |
| 26 | /** Synthesis id. */ |
| 27 | private final String mUtteranceId; |
| 28 | |
| 29 | /** Voice ID. */ |
Przemyslaw Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 30 | private final String mVoiceName; |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 31 | |
| 32 | /** Voice Parameters. */ |
| 33 | private final Bundle mVoiceParams; |
| 34 | |
| 35 | /** Audio Parameters. */ |
| 36 | private final Bundle mAudioParams; |
| 37 | |
| 38 | /** |
Przemyslaw Szczepaniak | 8399aae | 2013-11-22 13:08:01 +0000 | [diff] [blame] | 39 | * Constructor for test purposes. |
| 40 | */ |
Niels Egberts | a6cc9b8 | 2014-05-14 13:01:29 +0100 | [diff] [blame] | 41 | public SynthesisRequestV2(Markup markup, String utteranceId, String voiceName, |
Przemyslaw Szczepaniak | 8399aae | 2013-11-22 13:08:01 +0000 | [diff] [blame] | 42 | Bundle voiceParams, Bundle audioParams) { |
Niels Egberts | a6cc9b8 | 2014-05-14 13:01:29 +0100 | [diff] [blame] | 43 | this.mMarkup = markup; |
Przemyslaw Szczepaniak | 8399aae | 2013-11-22 13:08:01 +0000 | [diff] [blame] | 44 | this.mUtteranceId = utteranceId; |
| 45 | this.mVoiceName = voiceName; |
| 46 | this.mVoiceParams = voiceParams; |
| 47 | this.mAudioParams = audioParams; |
| 48 | } |
| 49 | |
| 50 | /** |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 51 | * Parcel based constructor. |
| 52 | * |
| 53 | * @hide |
| 54 | */ |
| 55 | public SynthesisRequestV2(Parcel in) { |
Niels Egberts | a6cc9b8 | 2014-05-14 13:01:29 +0100 | [diff] [blame] | 56 | this.mMarkup = (Markup) in.readValue(Markup.class.getClassLoader()); |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 57 | this.mUtteranceId = in.readString(); |
Przemyslaw Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 58 | this.mVoiceName = in.readString(); |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 59 | this.mVoiceParams = in.readBundle(); |
| 60 | this.mAudioParams = in.readBundle(); |
| 61 | } |
| 62 | |
Niels Egberts | a6cc9b8 | 2014-05-14 13:01:29 +0100 | [diff] [blame] | 63 | /** |
| 64 | * Constructor to request the synthesis of a sentence. |
| 65 | */ |
| 66 | SynthesisRequestV2(Markup markup, String utteranceId, RequestConfig rconfig) { |
| 67 | this.mMarkup = markup; |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 68 | this.mUtteranceId = utteranceId; |
Przemyslaw Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 69 | this.mVoiceName = rconfig.getVoice().getName(); |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 70 | this.mVoiceParams = rconfig.getVoiceParams(); |
| 71 | this.mAudioParams = rconfig.getAudioParams(); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Write to parcel. |
| 76 | * |
| 77 | * @hide |
| 78 | */ |
| 79 | @Override |
| 80 | public void writeToParcel(Parcel dest, int flags) { |
Niels Egberts | a6cc9b8 | 2014-05-14 13:01:29 +0100 | [diff] [blame] | 81 | dest.writeValue(mMarkup); |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 82 | dest.writeString(mUtteranceId); |
Przemyslaw Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 83 | dest.writeString(mVoiceName); |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 84 | dest.writeBundle(mVoiceParams); |
| 85 | dest.writeBundle(mAudioParams); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @return the text which should be synthesized. |
| 90 | */ |
| 91 | public String getText() { |
Niels Egberts | a6cc9b8 | 2014-05-14 13:01:29 +0100 | [diff] [blame] | 92 | if (mMarkup.getPlainText() == null) { |
| 93 | Log.e(TAG, "Plaintext of markup is null."); |
| 94 | return ""; |
| 95 | } |
| 96 | return mMarkup.getPlainText(); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @return the markup which should be synthesized. |
| 101 | */ |
| 102 | public Markup getMarkup() { |
| 103 | return mMarkup; |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @return the id of the synthesis request. It's an output of a call to the |
| 108 | * {@link UtteranceId#toUniqueString()} method of the {@link UtteranceId} associated with |
| 109 | * this request. |
| 110 | */ |
| 111 | public String getUtteranceId() { |
| 112 | return mUtteranceId; |
| 113 | } |
| 114 | |
| 115 | /** |
Przemyslaw Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 116 | * @return the name of the voice to use for this synthesis request. Result of a call to |
| 117 | * the {@link VoiceInfo#getName()} method. |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 118 | */ |
Przemyslaw Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 119 | public String getVoiceName() { |
| 120 | return mVoiceName; |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @return bundle of voice parameters. |
| 125 | */ |
| 126 | public Bundle getVoiceParams() { |
| 127 | return mVoiceParams; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * @return bundle of audio parameters. |
| 132 | */ |
| 133 | public Bundle getAudioParams() { |
| 134 | return mAudioParams; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Parcel creators. |
| 139 | * |
| 140 | * @hide |
| 141 | */ |
| 142 | public static final Parcelable.Creator<SynthesisRequestV2> CREATOR = |
| 143 | new Parcelable.Creator<SynthesisRequestV2>() { |
| 144 | @Override |
| 145 | public SynthesisRequestV2 createFromParcel(Parcel source) { |
| 146 | return new SynthesisRequestV2(source); |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public SynthesisRequestV2[] newArray(int size) { |
| 151 | return new SynthesisRequestV2[size]; |
| 152 | } |
| 153 | }; |
| 154 | |
| 155 | /** |
| 156 | * @hide |
| 157 | */ |
| 158 | @Override |
| 159 | public int describeContents() { |
| 160 | return 0; |
| 161 | } |
| 162 | } |