blob: a1da49cfc568e8a2cb04d4b6add2afdc558376cc [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;
7
8/**
9 * Service-side representation of a synthesis request from a V2 API client. Contains:
10 * <ul>
11 * <li>The utterance to synthesize</li>
12 * <li>The id of the utterance (String, result of {@link UtteranceId#toUniqueString()}</li>
Przemyslaw Szczepaniak97cd6472013-10-25 12:04:47 +010013 * <li>The synthesis voice name (String, result of {@link VoiceInfo#getName()})</li>
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010014 * <li>Voice parameters (Bundle of parameters)</li>
15 * <li>Audio parameters (Bundle of parameters)</li>
16 * </ul>
17 */
18public final class SynthesisRequestV2 implements Parcelable {
19 /** Synthesis utterance. */
20 private final String mText;
21
22 /** Synthesis id. */
23 private final String mUtteranceId;
24
25 /** Voice ID. */
Przemyslaw Szczepaniak97cd6472013-10-25 12:04:47 +010026 private final String mVoiceName;
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010027
28 /** Voice Parameters. */
29 private final Bundle mVoiceParams;
30
31 /** Audio Parameters. */
32 private final Bundle mAudioParams;
33
34 /**
Przemyslaw Szczepaniak8399aae2013-11-22 13:08:01 +000035 * Constructor for test purposes.
36 */
37 public SynthesisRequestV2(String text, String utteranceId, String voiceName,
38 Bundle voiceParams, Bundle audioParams) {
39 this.mText = text;
40 this.mUtteranceId = utteranceId;
41 this.mVoiceName = voiceName;
42 this.mVoiceParams = voiceParams;
43 this.mAudioParams = audioParams;
44 }
45
46 /**
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010047 * Parcel based constructor.
48 *
49 * @hide
50 */
51 public SynthesisRequestV2(Parcel in) {
52 this.mText = in.readString();
53 this.mUtteranceId = in.readString();
Przemyslaw Szczepaniak97cd6472013-10-25 12:04:47 +010054 this.mVoiceName = in.readString();
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010055 this.mVoiceParams = in.readBundle();
56 this.mAudioParams = in.readBundle();
57 }
58
59 SynthesisRequestV2(String text, String utteranceId, RequestConfig rconfig) {
60 this.mText = text;
61 this.mUtteranceId = utteranceId;
Przemyslaw Szczepaniak97cd6472013-10-25 12:04:47 +010062 this.mVoiceName = rconfig.getVoice().getName();
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010063 this.mVoiceParams = rconfig.getVoiceParams();
64 this.mAudioParams = rconfig.getAudioParams();
65 }
66
67 /**
68 * Write to parcel.
69 *
70 * @hide
71 */
72 @Override
73 public void writeToParcel(Parcel dest, int flags) {
74 dest.writeString(mText);
75 dest.writeString(mUtteranceId);
Przemyslaw Szczepaniak97cd6472013-10-25 12:04:47 +010076 dest.writeString(mVoiceName);
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +010077 dest.writeBundle(mVoiceParams);
78 dest.writeBundle(mAudioParams);
79 }
80
81 /**
82 * @return the text which should be synthesized.
83 */
84 public String getText() {
85 return mText;
86 }
87
88 /**
89 * @return the id of the synthesis request. It's an output of a call to the
90 * {@link UtteranceId#toUniqueString()} method of the {@link UtteranceId} associated with
91 * this request.
92 */
93 public String getUtteranceId() {
94 return mUtteranceId;
95 }
96
97 /**
Przemyslaw Szczepaniak97cd6472013-10-25 12:04:47 +010098 * @return the name of the voice to use for this synthesis request. Result of a call to
99 * the {@link VoiceInfo#getName()} method.
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +0100100 */
Przemyslaw Szczepaniak97cd6472013-10-25 12:04:47 +0100101 public String getVoiceName() {
102 return mVoiceName;
Przemyslaw Szczepaniak90d15d22013-06-14 12:02:53 +0100103 }
104
105 /**
106 * @return bundle of voice parameters.
107 */
108 public Bundle getVoiceParams() {
109 return mVoiceParams;
110 }
111
112 /**
113 * @return bundle of audio parameters.
114 */
115 public Bundle getAudioParams() {
116 return mAudioParams;
117 }
118
119 /**
120 * Parcel creators.
121 *
122 * @hide
123 */
124 public static final Parcelable.Creator<SynthesisRequestV2> CREATOR =
125 new Parcelable.Creator<SynthesisRequestV2>() {
126 @Override
127 public SynthesisRequestV2 createFromParcel(Parcel source) {
128 return new SynthesisRequestV2(source);
129 }
130
131 @Override
132 public SynthesisRequestV2[] newArray(int size) {
133 return new SynthesisRequestV2[size];
134 }
135 };
136
137 /**
138 * @hide
139 */
140 @Override
141 public int describeContents() {
142 return 0;
143 }
144}