SynthesisRequest.java revision df7deefe8ebcbd619f27e2d394d7e5d0d7af33d1
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16package android.speech.tts;
17
18import android.os.Bundle;
19
20/**
21 * Contains data required by engines to synthesize speech. This data is :
22 * <ul>
23 *   <li>The text to synthesize</li>
24 *   <li>The synthesis locale, represented as a language, country and a variant.
25 *   The language is an ISO 639-3 letter language code, and the country is an
26 *   ISO 3166 alpha 3 code. The variant is not specified.</li>
27 *   <li>The synthesis speech rate, with 100 being the normal, and
28 *   higher values representing higher speech rates.</li>
29 *   <li>The voice pitch, with 100 being the default pitch.</li>
30 * </ul>
31 *
32 * Any additional parameters sent to the text to speech service are passed in
33 * uninterpreted, see the {@code params} argument in {@link TextToSpeech#speak}
34 * and {@link TextToSpeech#synthesizeToFile}.
35 */
36public final class SynthesisRequest {
37    private final CharSequence mText;
38    private final Bundle mParams;
39    private String mLanguage;
40    private String mCountry;
41    private String mVariant;
42    private int mSpeechRate;
43    private int mPitch;
44    private int mCallerUid;
45
46    public SynthesisRequest(String text, Bundle params) {
47        mText = text;
48        // Makes a copy of params.
49        mParams = new Bundle(params);
50    }
51
52    public SynthesisRequest(CharSequence text, Bundle params) {
53        mText = text;
54        // Makes a copy of params.
55        mParams = new Bundle(params);
56    }
57
58    /**
59     * Gets the text which should be synthesized.
60     * @deprecated As of API level 20, replaced by {@link #getCharSequenceText}.
61     */
62    @Deprecated
63    public String getText() {
64        return mText.toString();
65    }
66
67    /**
68     * Gets the text which should be synthesized.
69     */
70    public CharSequence getCharSequenceText() {
71        return mText;
72    }
73
74    /**
75     * Gets the ISO 3-letter language code for the language to use.
76     */
77    public String getLanguage() {
78        return mLanguage;
79    }
80
81    /**
82     * Gets the ISO 3-letter country code for the language to use.
83     */
84    public String getCountry() {
85        return mCountry;
86    }
87
88    /**
89     * Gets the language variant to use.
90     */
91    public String getVariant() {
92        return mVariant;
93    }
94
95    /**
96     * Gets the speech rate to use. The normal rate is 100.
97     */
98    public int getSpeechRate() {
99        return mSpeechRate;
100    }
101
102    /**
103     * Gets the pitch to use. The normal pitch is 100.
104     */
105    public int getPitch() {
106        return mPitch;
107    }
108
109    /**
110     * Gets the additional params, if any.
111     */
112    public Bundle getParams() {
113        return mParams;
114    }
115
116    /**
117     * Gets the request caller Uid.
118     */
119    public int getCallerUid() {
120        return mCallerUid;
121    }
122
123    /**
124     * Sets the locale for the request.
125     */
126    void setLanguage(String language, String country, String variant) {
127        mLanguage = language;
128        mCountry = country;
129        mVariant = variant;
130    }
131
132    /**
133     * Sets the speech rate.
134     */
135    void setSpeechRate(int speechRate) {
136        mSpeechRate = speechRate;
137    }
138
139    /**
140     * Sets the pitch.
141     */
142    void setPitch(int pitch) {
143        mPitch = pitch;
144    }
145
146    /**
147     * Sets Caller Uid
148     */
149    void setCallerUid(int uid) {
150        mCallerUid = uid;
151    }
152}
153