KeyphraseMetadata.java revision d7018200312e4e4dc3f67cf33dc90bf7ce585844
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.hardware.soundtrigger; 18 19import android.util.ArraySet; 20 21/** 22 * A Voice Keyphrase metadata read from the enrollment application. 23 * 24 * @hide 25 */ 26public class KeyphraseMetadata { 27 public final int id; 28 public final String keyphrase; 29 public final ArraySet<String> supportedLocales; 30 31 public KeyphraseMetadata(int id, String keyphrase, String[] supportedLocales) { 32 this.id = id; 33 this.keyphrase = keyphrase; 34 this.supportedLocales = new ArraySet<String>(supportedLocales.length); 35 for (String locale : supportedLocales) { 36 this.supportedLocales.add(locale); 37 } 38 } 39 40 @Override 41 public String toString() { 42 return "id=" + id + ", keyphrase=" + keyphrase + ", supported-locales=" + supportedLocales; 43 } 44 45 /** 46 * @return Indicates if we support the given phrase. 47 */ 48 public boolean supportsPhrase(String phrase) { 49 // TODO(sansid): Come up with a scheme for custom keyphrases that should always match. 50 return keyphrase.equalsIgnoreCase(phrase); 51 } 52 53 /** 54 * @return Indicates if we support the given locale. 55 */ 56 public boolean supportsLocale(String locale) { 57 // TODO(sansid): Come up with a scheme for keyphrases that are available in all locales. 58 return supportedLocales.contains(locale); 59 } 60} 61