TtsSpan.java revision 36e08484abf1b9dbe26351276b6592be21eb7de4
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of 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,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.text.style;
18
19import android.os.Parcel;
20import android.os.PersistableBundle;
21import android.text.ParcelableSpan;
22import android.text.TextUtils;
23
24/**
25 * A span that supplies additional meta-data for the associated text intended
26 * for text-to-speech engines.  If the text is being processed by a
27 * text-to-speech engine, the engine may use the data in this span in addition
28 * to or instead of its associated text.
29 *
30 * The inner classes are there for convenience and provide builders for each
31 * TtsSpan type.
32 */
33public class TtsSpan implements ParcelableSpan {
34    private final String mType;
35    private final PersistableBundle mArgs;
36
37    /**
38     * This span type can be used to add morphosyntactic features to the text it
39     * spans over, or synthesize a something else than the spanned text.  Use
40     * the argument {@link #ARG_TEXT} to set a different text.
41     * Accepts the arguments {@link #ARG_GENDER},
42     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
43     * {@link #ARG_CASE}.
44     */
45    public static final String TYPE_TEXT = "android.type.text";
46
47    /**
48     * The text associated with this span is a cardinal.  Must include the
49     * number to be synthesized with {@link #ARG_NUMBER}.
50     * Also accepts the arguments {@link #ARG_GENDER},
51     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
52     * {@link #ARG_CASE}.
53     */
54    public static final String TYPE_CARDINAL = "android.type.cardinal";
55
56    /**
57     * The text associated with this span is an ordinal. Must include the
58     * number to be synthesized with {@link #ARG_NUMBER}.
59     * Also accepts the arguments {@link #ARG_GENDER},
60     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
61     * {@link #ARG_CASE}.
62     */
63    public static final String TYPE_ORDINAL = "android.type.ordinal";
64
65    /**
66     * The text associated with this span is a decimal number. Must include the
67     * number to be synthesized with {@link #ARG_INTEGER_PART} and
68     * {@link #ARG_FRACTIONAL_PART}.
69     * Also accepts the arguments {@link #ARG_GENDER},
70     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
71     * {@link #ARG_CASE}.
72     */
73    public static final String TYPE_DECIMAL = "android.type.decimal";
74
75    /**
76     * The text associated with this span is a fractional number. Must include
77     * the number to be synthesized with {@link #ARG_NUMERATOR} and
78     * {@link #ARG_DENOMINATOR}. {@link #ARG_INTEGER_PART} is optional
79     * Also accepts the arguments {@link #ARG_GENDER},
80     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
81     * {@link #ARG_CASE}.
82     */
83    public static final String TYPE_FRACTION = "android.type.fraction";
84
85    /**
86     * The text associated with this span is a measure, consisting of a number
87     * and a unit. The number can be a cardinal, decimal or a fraction. Set the
88     * number with the same arguments as {@link #TYPE_CARDINAL},
89     * {@link #TYPE_DECIMAL} or {@link #TYPE_FRACTION}. The unit can be
90     * specified with {@link #ARG_UNIT}.
91     * Also accepts the arguments {@link #ARG_GENDER},
92     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
93     * {@link #ARG_CASE}.
94     */
95    public static final String TYPE_MEASURE = "android.type.measure";
96
97    /**
98     * The text associated with this span is a time, consisting of a number of
99     * hours and minutes, specified with {@link #ARG_HOURS} and
100     * {@link #ARG_MINUTES}.
101     * Also accepts the arguments {@link #ARG_GENDER},
102     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
103     * {@link #ARG_CASE}.
104     */
105    public static final String TYPE_TIME = "android.type.time";
106
107    /**
108     * The text associated with this span is a date. All arguments are optional,
109     * but at least one has to be provided: {@link #ARG_WEEKDAY},
110     * {@link #ARG_DAY}, {@link #ARG_MONTH} and {@link #ARG_YEAR}.
111     * Also accepts the arguments {@link #ARG_GENDER},
112     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
113     * {@link #ARG_CASE}.
114     */
115    public static final String TYPE_DATE = "android.type.date";
116
117    /**
118     * The text associated with this span is a telephone number. The argument
119     * {@link #ARG_NUMBER_PART} is required. {@link #ARG_COUNTRY_CODE} and
120     * {@link #ARG_EXTENSION} are optional.
121     * Also accepts the arguments {@link #ARG_GENDER},
122     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
123     * {@link #ARG_CASE}.
124     */
125    public static final String TYPE_TELEPHONE = "android.type.telephone";
126
127
128    /**
129     * The text associated with this span is a URI (can be used for URLs and
130     * email addresses). The full schema for URLs, which email addresses can
131     * effectively be seen as a subset of, is:
132     * protocol://username:password@domain:port/path?query_string#fragment_id
133     * Hence populating just username and domain will read as an email address.
134     * All arguments are optional, but at least one has to be provided:
135     * {@link #ARG_PROTOCOL}, {@link #ARG_USERNAME}, {@link #ARG_PASSWORD},
136     * {@link #ARG_DOMAIN}, {@link #ARG_PORT}, {@link #ARG_PATH},
137     * {@link #ARG_QUERY_STRING} and {@link #ARG_FRAGMENT_ID}.
138     * Also accepts the arguments {@link #ARG_GENDER},
139     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
140     * {@link #ARG_CASE}.
141     */
142    public static final String TYPE_ELECTRONIC = "android.type.electronic";
143
144    /**
145     * The text associated with this span is a series of digits that have to be
146     * read sequentially. {@link #ARG_DIGITS} is required.
147     * Also accepts the arguments {@link #ARG_GENDER},
148     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
149     * {@link #ARG_CASE}.
150     */
151    public static final String TYPE_DIGITS = "android.type.digits";
152
153    /**
154     * The text associated with this span is a series of characters that have to
155     * be read verbatim. The engine will attempt to ready out any character like
156     * punctuation but excluding whitespace. {@link #ARG_VERBATIM} is required.
157     * Also accepts the arguments {@link #ARG_GENDER},
158     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
159     * {@link #ARG_CASE}.
160     */
161    public static final String TYPE_VERBATIM = "android.type.verbatim";
162
163    /**
164     * String argument supplying gender information.  Can be any of
165     * {@link #GENDER_NEUTRAL}, {@link #GENDER_MALE} and
166     * {@link #GENDER_FEMALE}.
167     */
168    public static final String ARG_GENDER = "android.arg.gender";
169
170    public static final String GENDER_NEUTRAL = "android.neutral";
171    public static final String GENDER_MALE = "android.male";
172    public static final String GENDER_FEMALE = "android.female";
173
174    /**
175     * String argument supplying animacy information.  Can be
176     * {@link #ANIMACY_ANIMATE} or
177     * {@link #ANIMACY_INANIMATE}
178     */
179    public static final String ARG_ANIMACY = "android.arg.animacy";
180
181    public static final String ANIMACY_ANIMATE = "android.animate";
182    public static final String ANIMACY_INANIMATE = "android.inanimate";
183
184    /**
185     * String argument supplying multiplicity information.  Can be any of
186     * {@link #MULTIPLICITY_SINGLE},
187     * {@link #MULTIPLICITY_DUAL} and
188     * {@link #MULTIPLICITY_PLURAL}
189     */
190    public static final String ARG_MULTIPLICITY = "android.arg.multiplicity";
191
192    public static final String MULTIPLICITY_SINGLE = "android.single";
193    public static final String MULTIPLICITY_DUAL = "android.dual";
194    public static final String MULTIPLICITY_PLURAL = "android.plural";
195
196    /**
197     * String argument supplying case information.  Can be any of
198     * {@link #CASE_NOMINATIVE}, {@link #CASE_ACCUSATIVE},
199     * {@link #CASE_DATIVE}, {@link #CASE_ABLATIVE},
200     * {@link #CASE_GENITIVE}, {@link #CASE_VOCATIVE},
201     * {@link #CASE_LOCATIVE} and
202     * {@link #CASE_INSTRUMENTAL}
203     */
204    public static final String ARG_CASE = "android.arg.case";
205
206    public static final String CASE_NOMINATIVE = "android.nomative";
207    public static final String CASE_ACCUSATIVE = "android.accusative";
208    public static final String CASE_DATIVE = "android.dative";
209    public static final String CASE_ABLATIVE = "android.ablative";
210    public static final String CASE_GENITIVE = "android.genitive";
211    public static final String CASE_VOCATIVE = "android.vocative";
212    public static final String CASE_LOCATIVE = "android.locative";
213    public static final String CASE_INSTRUMENTAL = "android.instrumental";
214
215    /**
216     * String supplying the text to be synthesized.  The synthesizer is free
217     * to decide how to interpret the text.
218     * Can be used with {@link #TYPE_TEXT}.
219     */
220    public static final String ARG_TEXT = "android.arg.text";
221
222    /**
223     * Argument used to specify a whole number.  The value can be a string of
224     * digits of any size optionally prefixed with a - or +.
225     * Can be used with {@link #TYPE_CARDINAL} and {@link #TYPE_ORDINAL}.
226     */
227    public static final String ARG_NUMBER = "android.arg.number";
228
229    /**
230     * Argument used to specify the integer part of a decimal or fraction. The
231     * value can be a string of digits of any size optionally prefixed with a - or +.
232     * Can be used with {@link #TYPE_DECIMAL} and {@link #TYPE_FRACTION}.
233     */
234    public static final String ARG_INTEGER_PART = "android.arg.integer_part";
235
236    /**
237     * Argument used to specify the fractional part of a decimal. The value can
238     * be a string of digits of any size.
239     * Can be used with {@link #TYPE_DECIMAL}.
240     */
241    public static final String ARG_FRACTIONAL_PART =
242        "android.arg.fractional_part";
243
244    /**
245     * Argument used to specify the numerator of a fraction. The value can be a
246     * string of digits of any size optionally prefixed with a - or +.
247     * Can be used with {@link #TYPE_FRACTION}.
248     */
249    public static final String ARG_NUMERATOR = "android.arg.numerator";
250
251    /**
252     * Argument used to specify the denominator of a fraction. The value can be
253     * a string of digits of any size optionally prefixed with a + or -.
254     * Can be used with {@link #TYPE_FRACTION}.
255     */
256    public static final String ARG_DENOMINATOR = "android.arg.denominator";
257
258    /**
259     * Argument used to specify the unit of a measure. The unit should always be
260     * specified in English singular form. Prefixes may be used. Engines will do
261     * their best to pronounce them correctly in the language used. Engines are
262     * expected to at least support the most common ones like 'meter', 'second',
263     * 'degree celcius' and 'degree fahrenheit' with some common prefixes like
264     * 'milli' and 'kilo'.
265     * Can be used with {@link #TYPE_MEASURE}.
266     */
267    public static final String ARG_UNIT = "android.arg.unit";
268
269    /**
270     * Argument used to specify the hours of a time. The hours should be
271     * provided as an integer in the range from 0 up to and including 24.
272     * Can be used with {@link #TYPE_TIME}.
273     */
274    public static final String ARG_HOURS = "android.arg.hours";
275
276    /**
277     * Argument used to specify the minutes of a time. The hours should be
278     * provided as an integer in the range from 0 up to and including 59.
279     * Can be used with {@link #TYPE_TIME}.
280     */
281    public static final String ARG_MINUTES = "android.arg.minutes";
282
283    /**
284     * Argument used to specify the weekday of a date. The value should be
285     * provided as an integer and can be any of {@link #WEEKDAY_SUNDAY},
286     * {@link #WEEKDAY_MONDAY}, {@link #WEEKDAY_TUESDAY},
287     * {@link #WEEKDAY_WEDNESDAY}, {@link #WEEKDAY_THURSDAY},
288     * {@link #WEEKDAY_FRIDAY} and {@link #WEEKDAY_SATURDAY}.
289     * Can be used with {@link #TYPE_DATE}.
290     */
291    public static final String ARG_WEEKDAY = "android.arg.weekday";
292
293    public static final int WEEKDAY_SUNDAY = 1;
294    public static final int WEEKDAY_MONDAY = 2;
295    public static final int WEEKDAY_TUESDAY = 3;
296    public static final int WEEKDAY_WEDNESDAY = 4;
297    public static final int WEEKDAY_THURSDAY = 5;
298    public static final int WEEKDAY_FRIDAY = 6;
299    public static final int WEEKDAY_SATURDAY = 7;
300
301    /**
302     * Argument used to specify the day of the month of a date. The value should
303     * be provided as an integer in the range from 1 up to and including 31.
304     * Can be used with {@link #TYPE_DATE}.
305     */
306    public static final String ARG_DAY = "android.arg.day";
307
308    /**
309     * Argument used to specify the month of a date. The value should be
310     * provided as an integer and can be any of {@link #MONTH_JANUARY},
311     * {@link #MONTH_FEBRUARY},  {@link #MONTH_MARCH}, {@link #MONTH_APRIL}, {@link #MONTH_MAY},
312     * {@link #MONTH_JUNE}, {@link #MONTH_JULY}, {@link #MONTH_AUGUST}, {@link #MONTH_SEPTEMBER},
313     * {@link #MONTH_OCTOBER}, {@link #MONTH_NOVEMBER} and {@link #MONTH_DECEMBER}.
314     * Can be used with {@link #TYPE_DATE}.
315     */
316    public static final String ARG_MONTH = "android.arg.month";
317
318    public static final int MONTH_JANUARY = 0;
319    public static final int MONTH_FEBRUARY = 1;
320    public static final int MONTH_MARCH = 2;
321    public static final int MONTH_APRIL = 3;
322    public static final int MONTH_MAY = 4;
323    public static final int MONTH_JUNE = 5;
324    public static final int MONTH_JULY = 6;
325    public static final int MONTH_AUGUST = 7;
326    public static final int MONTH_SEPTEMBER = 8;
327    public static final int MONTH_OCTOBER = 9;
328    public static final int MONTH_NOVEMBER = 10;
329    public static final int MONTH_DECEMBER = 11;
330
331    /**
332     * Argument used to specify the year of a date. The value should be provided
333     * as a positive integer.
334     * Can be used with {@link #TYPE_DATE}.
335     */
336    public static final String ARG_YEAR = "android.arg.year";
337
338    /**
339     * Argument used to specify the country code of a telephone number. Can be
340     * a string of digits.
341     * Can be used with {@link #TYPE_TELEPHONE}.
342     */
343    public static final String ARG_COUNTRY_CODE = "android.arg.country_code";
344
345    /**
346     * Argument used to specify the main number part of a telephone number. Can
347     * be a string of digits.
348     * Can be used with {@link #TYPE_TELEPHONE}.
349     */
350    public static final String ARG_NUMBER_PART = "android.arg.number_part";
351
352    /**
353     * Argument used to specify the extension part of a telephone number. Can be
354     * a string of digits.
355     * Can be used with {@link #TYPE_TELEPHONE}.
356     */
357    public static final String ARG_EXTENSION = "android.arg.extension";
358
359    /**
360     * Argument used to specify the protocol of a URI. Examples are 'http' and
361     * 'ftp'.
362     * Can be used with {@link #TYPE_ELECTRONIC}.
363     */
364    public static final String ARG_PROTOCOL = "android.arg.protocol";
365
366    /**
367     * Argument used to specify the username part of a URI. Should be set as a
368     * string.
369     * Can be used with {@link #TYPE_ELECTRONIC}.
370     */
371    public static final String ARG_USERNAME = "android.arg.username";
372
373    /**
374     * Argument used to specify the password part of a URI. Should be set as a
375     * string.
376     * Can be used with {@link #TYPE_ELECTRONIC}.
377     */
378    public static final String ARG_PASSWORD = "android.arg.password";
379
380    /**
381     * Argument used to specify the domain part of a URI. For example are
382     * 'source.android.com'.
383     * Can be used with {@link #TYPE_ELECTRONIC}.
384     */
385    public static final String ARG_DOMAIN = "android.arg.domain";
386
387    /**
388     * Argument used to specify the port number of a URI. Should be specified as
389     * an integer.
390     * Can be used with {@link #TYPE_ELECTRONIC}.
391     */
392    public static final String ARG_PORT = "android.arg.port";
393
394    /**
395     * Argument used to specify the path part of a URI. For example
396     * 'source/index.html'.
397     * Can be used with {@link #TYPE_ELECTRONIC}.
398     */
399    public static final String ARG_PATH = "android.arg.path";
400
401    /**
402     * Argument used to specify the query string of a URI. For example
403     * 'arg=value&argtwo=value'.
404     * Can be used with {@link #TYPE_ELECTRONIC}.
405     */
406    public static final String ARG_QUERY_STRING = "android.arg.query_string";
407
408    /**
409     * Argument used to specify the fragment id of a URI. Should be specified as
410     * a string.
411     * Can be used with {@link #TYPE_ELECTRONIC}.
412     */
413    public static final String ARG_FRAGMENT_ID = "android.arg.fragment_id";
414
415    /**
416     * Argument used to specify a string of digits.
417     * Can be used with {@link #TYPE_DIGITS}.
418     */
419    public static final String ARG_DIGITS = "android.arg.digits";
420
421    /**
422     * Argument used to specify a string where the characters are read verbatim,
423     * except whitespace.
424     * Can be used with {@link #TYPE_VERBATIM}.
425     */
426    public static final String ARG_VERBATIM = "android.arg.verbatim";
427
428    public TtsSpan(String type, PersistableBundle args) {
429        mType = type;
430        mArgs = args;
431    }
432
433    public TtsSpan(Parcel src) {
434        mType = src.readString();
435        mArgs = src.readPersistableBundle();
436    }
437
438    /**
439     * Returns the type.
440     * @return The type of this instance.
441     */
442    public String getType() {
443        return mType;
444    }
445
446    /**
447     * Returns a bundle of the arguments set.
448     * @return The bundle of the arguments set.
449     */
450    public PersistableBundle getArgs() {
451        return mArgs;
452    }
453
454    @Override
455    public int describeContents() {
456        return 0;
457    }
458
459    @Override
460    public void writeToParcel(Parcel dest, int flags) {
461        dest.writeString(mType);
462        dest.writePersistableBundle(mArgs);
463    }
464
465    @Override
466    public int getSpanTypeId() {
467        return TextUtils.TTS_SPAN;
468    }
469
470    /**
471     * A simple builder for TtsSpans.
472     * This builder can be used directly, but the more specific subclasses of
473     * this builder like {@link TtsSpan.TextBuilder} and
474     * {@link TtsSpan.CardinalBuilder} are likely more useful.
475     *
476     * This class uses generics so methods from this class can return instances of
477     * its child classes, resulting in a fluent API (CRTP pattern).
478     */
479    public static abstract class Builder<C extends Builder<C>> {
480        // Holds the type of this class.
481        private final String mType;
482
483        // Holds the arguments of this class. It only stores objects of type
484        // String, Integer and Long.
485        private PersistableBundle mArgs = new PersistableBundle();
486
487        public Builder(String type) {
488            mType = type;
489        }
490
491        /**
492         * Returns a TtsSpan built from the parameters set by the setter
493         * methods.
494         * @return A TtsSpan built with parameters of this builder.
495         */
496        public TtsSpan build() {
497            return new TtsSpan(mType, mArgs);
498        }
499
500        /**
501         * Sets an argument to a string value.
502         * @param arg The argument name.
503         * @param value The value the argument should be set to.
504         * @return This instance.
505         */
506        @SuppressWarnings("unchecked")
507        public C setStringArgument(String arg, String value) {
508            mArgs.putString(arg, value);
509            return (C) this;
510        }
511
512        /**
513         * Sets an argument to an int value.
514         * @param arg The argument name.
515         * @param value The value the argument should be set to.
516         */
517        @SuppressWarnings("unchecked")
518        public C setIntArgument(String arg, int value) {
519            mArgs.putInt(arg, value);
520            return (C) this;
521        }
522
523        /**
524         * Sets an argument to a long value.
525         * @param arg The argument name.
526         * @param value The value the argument should be set to.
527         */
528        @SuppressWarnings("unchecked")
529        public C setLongArgument(String arg, long value) {
530            mArgs.putLong(arg, value);
531            return (C) this;
532        }
533    }
534
535    /**
536     * A builder for TtsSpans, has setters for morphosyntactic features.
537     * This builder can be used directly, but the more specific subclasses of
538     * this builder like {@link TtsSpan.TextBuilder} and
539     * {@link TtsSpan.CardinalBuilder} are likely more useful.
540     */
541    public static class SemioticClassBuilder<C extends SemioticClassBuilder<C>>
542            extends Builder<C> {
543
544        public SemioticClassBuilder(String type) {
545            super(type);
546        }
547
548        /**
549         * Sets the gender information for this instance.
550         * @param gender Can any of {@link TtsSpan#GENDER_NEUTRAL},
551         *     {@link TtsSpan#GENDER_MALE} and {@link TtsSpan#GENDER_FEMALE}.
552         * @return This instance.
553         */
554        public C setGender(String gender) {
555            return setStringArgument(TtsSpan.ARG_GENDER, gender);
556        }
557
558        /**
559         * Sets the animacy information for this instance.
560         * @param animacy Can be any of {@link TtsSpan#ANIMACY_ANIMATE} and
561         *     {@link TtsSpan#ANIMACY_INANIMATE}.
562         * @return This instance.
563         */
564        public C setAnimacy(String animacy) {
565            return setStringArgument(TtsSpan.ARG_ANIMACY, animacy);
566        }
567
568        /**
569         * Sets the multiplicity information for this instance.
570         * @param multiplicity Can be any of
571         *     {@link TtsSpan#MULTIPLICITY_SINGLE},
572         *     {@link TtsSpan#MULTIPLICITY_DUAL} and
573         *     {@link TtsSpan#MULTIPLICITY_PLURAL}.
574         * @return This instance.
575         */
576        public C setMultiplicity(String multiplicity) {
577            return setStringArgument(TtsSpan.ARG_MULTIPLICITY, multiplicity);
578        }
579
580        /**
581         * Sets the grammatical case information for this instance.
582         * @param grammaticalCase Can be any of {@link TtsSpan#CASE_NOMINATIVE},
583         *     {@link TtsSpan#CASE_ACCUSATIVE}, {@link TtsSpan#CASE_DATIVE},
584         *     {@link TtsSpan#CASE_ABLATIVE}, {@link TtsSpan#CASE_GENITIVE},
585         *     {@link TtsSpan#CASE_VOCATIVE}, {@link TtsSpan#CASE_LOCATIVE} and
586         *     {@link TtsSpan#CASE_INSTRUMENTAL}.
587         * @return This instance.
588         */
589        public C setCase(String grammaticalCase) {
590            return setStringArgument(TtsSpan.ARG_CASE, grammaticalCase);
591        }
592    }
593
594    /**
595     * A builder for TtsSpans of type {@link TtsSpan #TYPE_TEXT}.
596     */
597    public static class TextBuilder extends SemioticClassBuilder<TextBuilder> {
598
599        /**
600         * Creates a TtsSpan of type {@link TtsSpan#TYPE_TEXT}.
601         */
602        public TextBuilder() {
603            super(TtsSpan.TYPE_TEXT);
604        }
605
606        /**
607         * Creates a TtsSpan of type {@link TtsSpan#TYPE_TEXT} and sets the
608         * {@link TtsSpan#ARG_TEXT} argument.
609         * @param text The text to be synthesized.
610         * @see #setText(String)
611         */
612        public TextBuilder(String text) {
613            this();
614            setText(text);
615        }
616
617        /**
618         * Sets the {@link TtsSpan#ARG_TEXT} argument, the text to be
619         * synthesized.
620         * @param text The string that will be synthesized.
621         * @return This instance.
622         */
623        public TextBuilder setText(String text) {
624            return setStringArgument(TtsSpan.ARG_TEXT, text);
625        }
626    }
627
628    /**
629     * A builder for TtsSpans of type {@link TtsSpan #TYPE_CARDINAL}.
630     */
631    public static class CardinalBuilder extends SemioticClassBuilder<CardinalBuilder> {
632
633        /**
634         * Creates a TtsSpan of type {@link TtsSpan#TYPE_CARDINAL}.
635         */
636        public CardinalBuilder() {
637            super(TtsSpan.TYPE_CARDINAL);
638        }
639
640        /**
641         * Creates a TtsSpan of type {@link TtsSpan#TYPE_CARDINAL} and sets the
642         * {@link TtsSpan#ARG_NUMBER} argument.
643         * @param number The number to synthesize.
644         * @see #setNumber(long)
645         */
646        public CardinalBuilder(long number) {
647            this();
648            setNumber(number);
649        }
650
651        /**
652         * Creates a TtsSpan of type {@link TtsSpan#TYPE_CARDINAL} and sets the
653         * {@link TtsSpan#ARG_NUMBER} argument.
654         * @param number The number to synthesize.
655         * @see #setNumber(String)
656         */
657        public CardinalBuilder(String number) {
658            this();
659            setNumber(number);
660        }
661
662        /**
663         * Convenience method that converts the number to a String and set it to
664         * the value for {@link TtsSpan#ARG_NUMBER}.
665         * @param number The number that will be synthesized.
666         * @return This instance.
667         */
668        public CardinalBuilder setNumber(long number) {
669            return setNumber(String.valueOf(number));
670        }
671
672        /**
673         * Sets the {@link TtsSpan#ARG_NUMBER} argument.
674         * @param number A non-empty string of digits with an optional
675         *     leading + or -.
676         * @return This instance.
677         */
678        public CardinalBuilder setNumber(String number) {
679            return setStringArgument(TtsSpan.ARG_NUMBER, number);
680        }
681    }
682}
683