diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/DialogProcessor.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/DialogProcessor.java index 869cc665d4..00a2860a78 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/DialogProcessor.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/DialogProcessor.java @@ -12,12 +12,9 @@ */ package org.openhab.core.voice.internal; -import static org.openhab.core.voice.internal.VoiceManagerImpl.getBestMatch; - import java.io.IOException; import java.util.HashSet; import java.util.Locale; -import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -87,7 +84,9 @@ public class DialogProcessor implements KSListener, STTListener { private final TranslationProvider i18nProvider; private final Bundle bundle; - private final @Nullable AudioFormat format; + private final @Nullable AudioFormat ksFormat; + private final @Nullable AudioFormat sttFormat; + private final @Nullable AudioFormat ttsFormat; /** * If the processor is currently processing a keyword event and thus should not spot further ones. @@ -120,14 +119,15 @@ public class DialogProcessor implements KSListener, STTListener { this.eventPublisher = eventPublisher; this.i18nProvider = i18nProvider; this.bundle = bundle; - this.format = AudioFormat.getBestMatch(source.getSupportedFormats(), sink.getSupportedFormats()); + this.ksFormat = AudioFormat.getBestMatch(source.getSupportedFormats(), ks.getSupportedFormats()); + this.sttFormat = AudioFormat.getBestMatch(source.getSupportedFormats(), stt.getSupportedFormats()); + this.ttsFormat = AudioFormat.getBestMatch(sink.getSupportedFormats(), tts.getSupportedFormats()); } public void start() { - AudioFormat fmt = format; + AudioFormat fmt = ksFormat; if (fmt == null) { - logger.warn("No compatible audio format found between source '{}' and sink '{}'", source.getId(), - sink.getId()); + logger.warn("No compatible audio format found for ks '{}' and source '{}'", ks.getId(), source.getId()); return; } abortKS(); @@ -213,7 +213,7 @@ public class DialogProcessor implements KSListener, STTListener { abortSTT(); closeStreamSTT(); isSTTServerAborting = false; - AudioFormat fmt = format; + AudioFormat fmt = sttFormat; if (fmt != null) { try { AudioStream stream = source.getInputStream(fmt); @@ -231,6 +231,9 @@ public class DialogProcessor implements KSListener, STTListener { say(text.replace("{0}", "")); } } + } else { + logger.warn("No compatible audio format found for stt '{}' and source '{}'", stt.getId(), + source.getId()); } } else if (ksEvent instanceof KSErrorEvent) { KSErrorEvent kse = (KSErrorEvent) ksEvent; @@ -294,8 +297,7 @@ public class DialogProcessor implements KSListener, STTListener { throw new TTSException("Unable to find a suitable voice"); } - Set audioFormats = tts.getSupportedFormats(); - AudioFormat audioFormat = getBestMatch(audioFormats, sink.getSupportedFormats()); + AudioFormat audioFormat = ttsFormat; if (audioFormat == null) { throw new TTSException("No compatible audio format found for TTS '" + tts.getId() + "' and sink '" + sink.getId() + "'"); diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceManagerImpl.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceManagerImpl.java index 552bd74f1c..07f96d8b90 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceManagerImpl.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceManagerImpl.java @@ -225,19 +225,19 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider { throw new TTSException( "Unable to find a voice for language " + localeProvider.getLocale().getLanguage()); } - Set audioFormats = tts.getSupportedFormats(); + Set sttAudioFormats = tts.getSupportedFormats(); AudioSink sink = audioManager.getSink(sinkId); if (sink == null) { throw new TTSException("Unable to find the audio sink " + sinkId); } - AudioFormat audioFormat = getBestMatch(audioFormats, sink.getSupportedFormats()); - if (audioFormat == null) { + AudioFormat sttAudioFormat = AudioFormat.getBestMatch(sink.getSupportedFormats(), sttAudioFormats); + if (sttAudioFormat == null) { throw new TTSException("No compatible audio format found for TTS '" + tts.getId() + "' and sink '" + sink.getId() + "'"); } - AudioStream audioStream = tts.synthesize(text, voice, audioFormat); + AudioStream audioStream = tts.synthesize(text, voice, sttAudioFormat); if (!sink.getSupportedStreams().stream().anyMatch(clazz -> clazz.isInstance(audioStream))) { throw new TTSException( "Failed playing audio stream '" + audioStream + "' as audio sink doesn't support it"); @@ -426,22 +426,6 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider { return null; } - public static @Nullable AudioFormat getBestMatch(Set inputs, Set outputs) { - AudioFormat preferredFormat = getPreferredFormat(inputs); - for (AudioFormat output : outputs) { - if (output.isCompatible(preferredFormat)) { - return preferredFormat; - } else { - for (AudioFormat input : inputs) { - if (output.isCompatible(input)) { - return input; - } - } - } - } - return null; - } - @Override public @Nullable Voice getPreferredVoice(Set voices) { // Express preferences with a Language Priority List