Debian Codegraph @

android/src/com/reecedunn/espeak/Voice.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2012-2013 Reece H. Dunn
3 * Copyright (C) 2011 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package com.reecedunn.espeak;
19
20 import java.util.Locale;
21 import java.util.MissingResourceException;
22
23 import android.speech.tts.TextToSpeech;
24
25 public class Voice {
26 public final String name;
27 public final String identifier;
28 public final int gender;
29 public final int age;
30 public final Locale locale;
31
32 public Voice(String name, String identifier, int gender, int age, Locale locale) {
33 this.name = name;
34 this.identifier = identifier;
35 this.gender = gender;
36 this.age = age;
37 this.locale = locale;
38 }
39
40 /**
41 * Attempts a partial match against a query locale.
42 *
43 * @param query The locale to match.
44 * @return A text-to-speech availability code. One of:
45 * <ul>
46 * <li>{@link TextToSpeech#LANG_NOT_SUPPORTED}
47 * <li>{@link TextToSpeech#LANG_AVAILABLE}
48 * <li>{@link TextToSpeech#LANG_COUNTRY_AVAILABLE}
49 * <li>{@link TextToSpeech#LANG_COUNTRY_VAR_AVAILABLE}
50 * </ul>
51 */
52 public int match(Locale query) {
53 if (!locale.getISO3Language().equals(query.getISO3Language())) {
54 return TextToSpeech.LANG_NOT_SUPPORTED;
55 }
56 try {
57 if (!locale.getISO3Country().equals(query.getISO3Country())) {
58 return TextToSpeech.LANG_AVAILABLE;
59 }
60 } catch (MissingResourceException e) {
61 return TextToSpeech.LANG_AVAILABLE;
62 }
63 if (!locale.getVariant().equals(query.getVariant())) {
64 return TextToSpeech.LANG_COUNTRY_AVAILABLE;
65 }
66 return TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE;
67 }
68
69 @Override
70 public String toString() {
71 String ret = locale.getISO3Language();
72 if (locale.getISO3Country() != null && !locale.getISO3Country().isEmpty()) {
73 ret += '-';
74 ret += locale.getISO3Country();
75 }
76 if (locale.getVariant() != null && !locale.getVariant().isEmpty()) {
77 ret += '-';
78 ret += locale.getVariant();
79 }
80 return ret;
81 }
82 }