2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.voice.pollytts.internal.cloudapi;
15 import java.util.List;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
21 * This class implements the PollyTTS configuration.
23 * @author Robert Hillman - Initial contribution
25 public class PollyTTSConfig {
27 private static final String ACCESS_KEY = "accessKey";
28 private static final String SECRET_KEY = "secretKey";
29 private static final String SERVICE_REGION = "serviceRegion";
30 private static final String AUDIO_FORMAT = "audioFormat";
31 private static final String CACHE_EXPIRATION = "cacheExpiration";
33 private String accessKey = "";
34 private String secretKey = "";
35 private String serviceRegion = "eu-west-1";
36 private int expireDate = 0;
37 private String audioFormat = "default";
38 private long lastDelete;
40 public PollyTTSConfig(Map<String, Object> config) {
41 assertValidConfig(config);
43 accessKey = config.getOrDefault(ACCESS_KEY, accessKey).toString();
44 secretKey = config.getOrDefault(SECRET_KEY, secretKey).toString();
45 serviceRegion = config.getOrDefault(SERVICE_REGION, serviceRegion).toString();
46 audioFormat = config.getOrDefault(AUDIO_FORMAT, audioFormat).toString();
47 expireDate = (int) Double
48 .parseDouble(config.getOrDefault(CACHE_EXPIRATION, Double.toString(expireDate)).toString());
51 private void assertValidConfig(Map<String, Object> config) {
52 List<String> emptyParams = Stream.of(ACCESS_KEY, SECRET_KEY, SERVICE_REGION)
53 .filter(param -> config.get(param) == null || config.get(param).toString().isEmpty())
54 .collect(Collectors.toList());
56 if (!emptyParams.isEmpty()) {
57 throw new IllegalArgumentException(
58 "Missing configuration parameters: " + emptyParams.stream().collect(Collectors.joining(", ")));
62 public String getAccessKey() {
66 public String getSecretKey() {
70 public String getServiceRegion() {
75 * get the life time for cache files
77 public int getExpireDate() {
82 * returns audio format specified for audio
84 public String getAudioFormat() {
89 * get the date when cache was cleaned last
91 public long getLastDelete() {
96 * set the date when cache was cleaned last
98 public void setLastDelete(long lastDelete) {
99 this.lastDelete = lastDelete;
103 public String toString() {
104 StringBuilder builder = new StringBuilder();
105 builder.append("PollyTTSConfig [accessKey=").append(accessKey).append(", secretKey=").append(secretKey)
106 .append(", serviceRegion=").append(serviceRegion).append(", expireDate=").append(expireDate)
107 .append(", audioFormat=").append(audioFormat).append(", lastDelete=").append(lastDelete).append("]");
108 return builder.toString();