blob: 130e3f956aaf9bac16d9aad28798d260d7e49989 [file] [log] [blame]
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +01001package android.speech.tts;
2
3import android.os.Bundle;
4import android.os.Parcel;
5import android.os.Parcelable;
6import android.speech.tts.TextToSpeechClient.UtteranceId;
Niels Egbertsa6cc9b82014-05-14 13:01:29 +01007import android.util.Log;
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +01008
9/**
10 * Service-side representation of a synthesis request from a V2 API client. Contains:
11 * <ul>
Niels Egbertsa6cc9b82014-05-14 13:01:29 +010012 * <li>The markup object to synthesize containing the utterance.</li>
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010013 * <li>The id of the utterance (String, result of {@link UtteranceId#toUniqueString()}</li>
Przemyslaw Szczepaniak97cd6472013-10-25 12:04:47 +010014 * <li>The synthesis voice name (String, result of {@link VoiceInfo#getName()})</li>
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010015 * <li>Voice parameters (Bundle of parameters)</li>
16 * <li>Audio parameters (Bundle of parameters)</li>
17 * </ul>
18 */
19public final class SynthesisRequestV2 implements Parcelable {
Niels Egbertsa6cc9b82014-05-14 13:01:29 +010020
21 private static final String TAG = "SynthesisRequestV2";
22
23 /** Synthesis markup */
24 private final Markup mMarkup;
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010025
26 /** Synthesis id. */
27 private final String mUtteranceId;
28
29 /** Voice ID. */
Przemyslaw Szczepaniak97cd6472013-10-25 12:04:47 +010030 private final String mVoiceName;
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010031
32 /** Voice Parameters. */
33 private final Bundle mVoiceParams;
34
35 /** Audio Parameters. */
36 private final Bundle mAudioParams;
37
38 /**
Przemyslaw Szczepaniak8399aae2013-11-22 13:08:01 +000039 * Constructor for test purposes.
40 */
Niels Egbertsa6cc9b82014-05-14 13:01:29 +010041 public SynthesisRequestV2(Markup markup, String utteranceId, String voiceName,
Przemyslaw Szczepaniak8399aae2013-11-22 13:08:01 +000042 Bundle voiceParams, Bundle audioParams) {
Niels Egbertsa6cc9b82014-05-14 13:01:29 +010043 this.mMarkup = markup;
Przemyslaw Szczepaniak8399aae2013-11-22 13:08:01 +000044 this.mUtteranceId = utteranceId;
45 this.mVoiceName = voiceName;
46 this.mVoiceParams = voiceParams;
47 this.mAudioParams = audioParams;
48 }
49
50 /**
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010051 * Parcel based constructor.
52 *
53 * @hide
54 */
55 public SynthesisRequestV2(Parcel in) {
Niels Egbertsa6cc9b82014-05-14 13:01:29 +010056 this.mMarkup = (Markup) in.readValue(Markup.class.getClassLoader());
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010057 this.mUtteranceId = in.readString();
Przemyslaw Szczepaniak97cd6472013-10-25 12:04:47 +010058 this.mVoiceName = in.readString();
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010059 this.mVoiceParams = in.readBundle();
60 this.mAudioParams = in.readBundle();
61 }
62
Niels Egbertsa6cc9b82014-05-14 13:01:29 +010063 /**
64 * Constructor to request the synthesis of a sentence.
65 */
66 SynthesisRequestV2(Markup markup, String utteranceId, RequestConfig rconfig) {
67 this.mMarkup = markup;
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010068 this.mUtteranceId = utteranceId;
Przemyslaw Szczepaniak97cd6472013-10-25 12:04:47 +010069 this.mVoiceName = rconfig.getVoice().getName();
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010070 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 Egbertsa6cc9b82014-05-14 13:01:29 +010081 dest.writeValue(mMarkup);
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010082 dest.writeString(mUtteranceId);
Przemyslaw Szczepaniak97cd6472013-10-25 12:04:47 +010083 dest.writeString(mVoiceName);
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010084 dest.writeBundle(mVoiceParams);
85 dest.writeBundle(mAudioParams);
86 }
87
88 /**
89 * @return the text which should be synthesized.
90 */
91 public String getText() {
Niels Egbertsa6cc9b82014-05-14 13:01:29 +010092 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 Szczepaniak90d15d22013-06-14 12:02:53 +0100104 }
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 Szczepaniak97cd6472013-10-25 12:04:47 +0100116 * @return the name of the voice to use for this synthesis request. Result of a call to
117 * the {@link VoiceInfo#getName()} method.
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +0100118 */
Przemyslaw Szczepaniak97cd6472013-10-25 12:04:47 +0100119 public String getVoiceName() {
120 return mVoiceName;
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +0100121 }
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}