TtsSpan.java revision 4f4ead481270d48f0374c40e72a77619a4ac2873
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 addition meta-data intended for text-to-speech rendering 26 * of the associated text. If the text is being processed by a text-to-speech 27 * engine, the engine may use the data in this span in addition to or instead of 28 * its associated text. 29 */ 30public class TtsSpan implements ParcelableSpan { 31 private final String mType; 32 private final PersistableBundle mArgs; 33 34 /** 35 * This span type can be used to add morphosyntactic features to the text it 36 * spans over, or synthesize a something else than the spanned text. Use 37 * the argument {@link #ARG_TEXT} to set a different text. 38 * Accepts the arguments {@link TtsSpan#ARG_GENDER}, 39 * {@link TtsSpan#ARG_ANIMACY}, {@link TtsSpan#ARG_MULTIPLICITY} and 40 * {@link TtsSpan#ARG_CASE}. 41 */ 42 public static final String TYPE_TEXT = "android.type.text"; 43 44 /** 45 * The text associated with this span is a cardinal. Must include the 46 * number to be synthesized with {@link #ARG_NUMBER}. 47 * Also accepts the arguments {@link TtsSpan#ARG_GENDER}, 48 * {@link TtsSpan#ARG_ANIMACY}, {@link TtsSpan#ARG_MULTIPLICITY} and 49 * {@link TtsSpan#ARG_CASE}. 50 */ 51 public static final String TYPE_CARDINAL = "android.type.cardinal"; 52 53 /** 54 * String supplying the text to be synthesized. The synthesizer is free 55 * to decide how to interpret the text. 56 */ 57 public static final String ARG_TEXT = "android.arg.text"; 58 59 /** 60 * Argument used to specify a whole number. The value can be a string of 61 * digits of any size optionally prefixed with a - or +. 62 */ 63 public static final String ARG_NUMBER = "android.arg.number"; 64 65 /** 66 * String argument supplying gender information. Can be any of 67 * {@link TtsSpan#GENDER_NEUTRAL}, {@link TtsSpan#GENDER_MALE} and 68 * {@link TtsSpan#GENDER_FEMALE}. 69 */ 70 public static final String ARG_GENDER = "android.arg.gender"; 71 72 public static final String GENDER_NEUTRAL = "android.neutral"; 73 public static final String GENDER_MALE = "android.male"; 74 public static final String GENDER_FEMALE = "android.female"; 75 76 /** 77 * String argument supplying animacy information. Can be 78 * {@link TtsSpan#ANIMACY_ANIMATE} or 79 * {@link TtsSpan#ANIMACY_INANIMATE} 80 */ 81 public static final String ARG_ANIMACY = "android.arg.animacy"; 82 83 public static final String ANIMACY_ANIMATE = "android.animate"; 84 public static final String ANIMACY_INANIMATE = "android.inanimate"; 85 86 /** 87 * String argument supplying multiplicity information. Can be any of 88 * {@link TtsSpan#MULTIPLICITY_SINGLE}, 89 * {@link TtsSpan#MULTIPLICITY_DUAL} and 90 * {@link TtsSpan#MULTIPLICITY_PLURAL} 91 */ 92 public static final String ARG_MULTIPLICITY = "android.arg.multiplicity"; 93 94 public static final String MULTIPLICITY_SINGLE = "android.single"; 95 public static final String MULTIPLICITY_DUAL = "android.dual"; 96 public static final String MULTIPLICITY_PLURAL = "android.plural"; 97 98 /** 99 * String argument supplying case information. Can be any of 100 * {@link TtsSpan#CASE_NOMINATIVE}, {@link TtsSpan#CASE_ACCUSATIVE}, 101 * {@link TtsSpan#CASE_DATIVE}, {@link TtsSpan#CASE_ABLATIVE}, 102 * {@link TtsSpan#CASE_GENITIVE}, {@link TtsSpan#CASE_VOCATIVE}, 103 * {@link TtsSpan#CASE_LOCATIVE} and 104 * {@link TtsSpan#CASE_INSTRUMENTAL} 105 */ 106 public static final String ARG_CASE = "android.arg.case"; 107 108 public static final String CASE_NOMINATIVE = "android.nomative"; 109 public static final String CASE_ACCUSATIVE = "android.accusative"; 110 public static final String CASE_DATIVE = "android.dative"; 111 public static final String CASE_ABLATIVE = "android.ablative"; 112 public static final String CASE_GENITIVE = "android.genitive"; 113 public static final String CASE_VOCATIVE = "android.vocative"; 114 public static final String CASE_LOCATIVE = "android.locative"; 115 public static final String CASE_INSTRUMENTAL = "android.instrumental"; 116 117 public TtsSpan(String type, PersistableBundle args) { 118 mType = type; 119 mArgs = args; 120 } 121 122 public TtsSpan(Parcel src) { 123 mType = src.readString(); 124 mArgs = src.readPersistableBundle(); 125 } 126 127 public String getType() { 128 return mType; 129 } 130 131 public PersistableBundle getArgs() { 132 return mArgs; 133 } 134 135 @Override 136 public int describeContents() { 137 return 0; 138 } 139 140 @Override 141 public void writeToParcel(Parcel dest, int flags) { 142 dest.writeString(mType); 143 dest.writePersistableBundle(mArgs); 144 } 145 146 @Override 147 public int getSpanTypeId() { 148 return TextUtils.TTS_SPAN; 149 } 150} 151