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.picotts.internal;
15 import java.util.Collections;
16 import java.util.Locale;
18 import java.util.stream.Collectors;
19 import java.util.stream.Stream;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.core.audio.AudioException;
24 import org.openhab.core.audio.AudioFormat;
25 import org.openhab.core.audio.AudioStream;
26 import org.openhab.core.voice.TTSException;
27 import org.openhab.core.voice.TTSService;
28 import org.openhab.core.voice.Voice;
29 import org.osgi.service.component.annotations.Component;
32 * @author Florian Schmidt - Initial Contribution
36 public class PicoTTSService implements TTSService {
37 private final Set<Voice> voices = Stream
38 .of(new PicoTTSVoice("de-DE"), new PicoTTSVoice("en-US"), new PicoTTSVoice("en-GB"),
39 new PicoTTSVoice("es-ES"), new PicoTTSVoice("fr-FR"), new PicoTTSVoice("it-IT"))
40 .collect(Collectors.toSet());
42 private final Set<AudioFormat> audioFormats = Collections.singleton(
43 new AudioFormat(AudioFormat.CONTAINER_WAVE, AudioFormat.CODEC_PCM_SIGNED, false, 16, null, 16000L));
46 public Set<Voice> getAvailableVoices() {
51 public Set<AudioFormat> getSupportedFormats() {
52 return this.audioFormats;
56 public AudioStream synthesize(String text, Voice voice, AudioFormat requestedFormat) throws TTSException {
58 throw new TTSException("The passed text can not be empty");
61 if (!this.voices.contains(voice)) {
62 throw new TTSException("The passed voice is unsupported");
65 boolean isAudioFormatSupported = this.audioFormats.stream().anyMatch(audioFormat -> {
66 return audioFormat.isCompatible(requestedFormat);
69 if (!isAudioFormatSupported) {
70 throw new TTSException("The passed AudioFormat is unsupported");
74 return new PicoTTSAudioStream(text, voice, requestedFormat);
75 } catch (AudioException e) {
76 throw new TTSException(e);
81 public String getId() {
86 public String getLabel(@Nullable Locale locale) {