KeyphraseMetadata.java revision e6cd2476aa9d07df0de0a0081ab66d8401a7e228
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    public final int recognitionModeFlags;
31
32    public KeyphraseMetadata(int id, String keyphrase, String[] supportedLocales,
33            int recognitionModeFlags) {
34        this.id = id;
35        this.keyphrase = keyphrase;
36        this.supportedLocales = new ArraySet<String>(supportedLocales.length);
37        for (String locale : supportedLocales) {
38            this.supportedLocales.add(locale);
39        }
40        this.recognitionModeFlags = recognitionModeFlags;
41    }
42
43    @Override
44    public String toString() {
45        return "id=" + id + ", keyphrase=" + keyphrase + ", supported-locales=" + supportedLocales
46                + ", recognition-modes=" + recognitionModeFlags;
47    }
48
49    /**
50     * @return Indicates if we support the given phrase.
51     */
52    public boolean supportsPhrase(String phrase) {
53        return keyphrase.isEmpty() || keyphrase.equalsIgnoreCase(phrase);
54    }
55
56    /**
57     * @return Indicates if we support the given locale.
58     */
59    public boolean supportsLocale(String locale) {
60        return supportedLocales.isEmpty() || supportedLocales.contains(locale);
61    }
62}
63