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; |
| 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 Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 13 | * <li>The synthesis voice name (String, result of {@link VoiceInfo#getName()})</li> |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 14 | * <li>Voice parameters (Bundle of parameters)</li> |
| 15 | * <li>Audio parameters (Bundle of parameters)</li> |
| 16 | * </ul> |
| 17 | */ |
| 18 | public 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 Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 26 | private final String mVoiceName; |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 27 | |
| 28 | /** Voice Parameters. */ |
| 29 | private final Bundle mVoiceParams; |
| 30 | |
| 31 | /** Audio Parameters. */ |
| 32 | private final Bundle mAudioParams; |
| 33 | |
| 34 | /** |
Przemyslaw Szczepaniak | 8399aae | 2013-11-22 13:08:01 +0000 | [diff] [blame] | 35 | * 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 Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 47 | * Parcel based constructor. |
| 48 | * |
| 49 | * @hide |
| 50 | */ |
| 51 | public SynthesisRequestV2(Parcel in) { |
| 52 | this.mText = in.readString(); |
| 53 | this.mUtteranceId = in.readString(); |
Przemyslaw Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 54 | this.mVoiceName = in.readString(); |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 55 | 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 Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 62 | this.mVoiceName = rconfig.getVoice().getName(); |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 63 | 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 Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 76 | dest.writeString(mVoiceName); |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 77 | 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 Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 98 | * @return the name of the voice to use for this synthesis request. Result of a call to |
| 99 | * the {@link VoiceInfo#getName()} method. |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 100 | */ |
Przemyslaw Szczepaniak | 97cd647 | 2013-10-25 12:04:47 +0100 | [diff] [blame] | 101 | public String getVoiceName() { |
| 102 | return mVoiceName; |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 103 | } |
| 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 | } |