]> git.basschouten.com Git - openhab-addons.git/blob
0e5f3afd0e34953d349f204b649a8c025e9faffa
[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.googletts.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.googletts.internal.dto.SsmlVoiceGender;
20
21 /**
22  * Implementation of the Voice interface for Google Cloud TTS Service.
23  *
24  * @author Gabor Bicskei - Initial contribution
25  */
26 @NonNullByDefault
27 public class GoogleTTSVoice implements Voice {
28
29     /**
30      * Voice locale
31      */
32     private final Locale locale;
33
34     /**
35      * Voice label
36      */
37     private final String label;
38
39     /**
40      * Gender
41      */
42     private final String ssmlGender;
43
44     /**
45      * Constructs a Google Cloud TTS Voice for the passed data
46      *
47      * @param locale The Locale of the voice
48      * @param label The label of the voice
49      * @param ssmlGender Voice gender
50      */
51     GoogleTTSVoice(Locale locale, String label, String ssmlGender) {
52         this.locale = locale;
53         this.ssmlGender = ssmlGender;
54         this.label = label;
55     }
56
57     /**
58      * Globally unique identifier of the voice.
59      *
60      * @return A String uniquely identifying the voice globally
61      */
62     @Override
63     public String getUID() {
64         return "googletts:" + getTechnicalName();
65     }
66
67     /**
68      * Technical name of the voice.
69      *
70      * @return A String voice technical name
71      */
72     String getTechnicalName() {
73         return label.replaceAll("[^a-zA-Z0-9_]", "");
74     }
75
76     /**
77      * The voice label, used for GUI's or VUI's
78      *
79      * @return The voice label, may not be globally unique
80      */
81     @Override
82     public String getLabel() {
83         return this.label;
84     }
85
86     /**
87      * {@inheritDoc}
88      */
89     @Override
90     public Locale getLocale() {
91         return this.locale;
92     }
93
94     /**
95      * The voice gender.
96      *
97      * @return {@link SsmlVoiceGender} enum name.
98      */
99     String getSsmlGender() {
100         return ssmlGender;
101     }
102 }