]> git.basschouten.com Git - openhab-addons.git/blob
d771f9677a942a23b514bf283a17765f04276213
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.voice.voicerss.internal;
14
15 import java.util.Locale;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.voice.Voice;
19 import org.openhab.voice.voicerss.internal.cloudapi.VoiceRSSCloudImpl;
20
21 /**
22  * Implementation of the Voice interface for VoiceRSS. Label is only "default"
23  * as only voice supported.
24  *
25  * @author Jochen Hiller - Initial contribution and API
26  */
27 @NonNullByDefault
28 public class VoiceRSSVoice implements Voice {
29
30     /**
31      * Voice locale
32      */
33     private final Locale locale;
34
35     /**
36      * Voice label
37      */
38     private final String label;
39
40     /**
41      * Constructs a VoiceRSS Voice for the passed data
42      *
43      * @param locale
44      *            The Locale of the voice
45      * @param label
46      *            The label of the voice
47      */
48     public VoiceRSSVoice(Locale locale, String label) {
49         this.locale = locale;
50         this.label = label;
51     }
52
53     /**
54      * Globally unique identifier of the voice.
55      *
56      * @return A String uniquely identifying the voice globally
57      */
58     @Override
59     public String getUID() {
60         String uid = "voicerss:" + locale.toLanguageTag().replaceAll("[^a-zA-Z0-9_]", "");
61         if (!label.equals(VoiceRSSCloudImpl.DEFAULT_VOICE)) {
62             uid += "_" + label.replaceAll("[^a-zA-Z0-9_]", "");
63         }
64         return uid;
65     }
66
67     /**
68      * The voice label, used for GUI's or VUI's
69      *
70      * @return The voice label, may not be globally unique
71      */
72     @Override
73     public String getLabel() {
74         return label;
75     }
76
77     /**
78      * {@inheritDoc}
79      */
80     @Override
81     public Locale getLocale() {
82         return locale;
83     }
84 }