2 * Copyright (c) 2010-2021 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.openhab.core.audio.AudioException;
22 import org.openhab.core.audio.AudioFormat;
23 import org.openhab.core.audio.AudioStream;
24 import org.openhab.core.voice.TTSException;
25 import org.openhab.core.voice.TTSService;
26 import org.openhab.core.voice.Voice;
27 import org.osgi.service.component.annotations.Component;
30 * @author Florian Schmidt - Initial Contribution
33 public class PicoTTSService implements TTSService {
34 private final Set<Voice> voices = Stream
35 .of(new PicoTTSVoice("de-DE"), new PicoTTSVoice("en-US"), new PicoTTSVoice("en-GB"),
36 new PicoTTSVoice("es-ES"), new PicoTTSVoice("fr-FR"), new PicoTTSVoice("it-IT"))
37 .collect(Collectors.toSet());
39 private final Set<AudioFormat> audioFormats = Collections.singleton(
40 new AudioFormat(AudioFormat.CONTAINER_WAVE, AudioFormat.CODEC_PCM_SIGNED, false, 16, null, 16000L));
43 public Set<Voice> getAvailableVoices() {
48 public Set<AudioFormat> getSupportedFormats() {
49 return this.audioFormats;
53 public AudioStream synthesize(String text, Voice voice, AudioFormat requestedFormat) throws TTSException {
54 if (text == null || text.isEmpty()) {
55 throw new TTSException("The passed text can not be null or empty");
58 if (!this.voices.contains(voice)) {
59 throw new TTSException("The passed voice is unsupported");
62 boolean isAudioFormatSupported = this.audioFormats.stream().anyMatch(audioFormat -> {
63 return audioFormat.isCompatible(requestedFormat);
66 if (!isAudioFormatSupported) {
67 throw new TTSException("The passed AudioFormat is unsupported");
71 return new PicoTTSAudioStream(text, voice, requestedFormat);
72 } catch (AudioException e) {
73 throw new TTSException(e);
78 public String getId() {
83 public String getLabel(Locale locale) {