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 00a2860a78..d721ffc722 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 @@ -119,9 +119,9 @@ public class DialogProcessor implements KSListener, STTListener { this.eventPublisher = eventPublisher; this.i18nProvider = i18nProvider; this.bundle = bundle; - this.ksFormat = AudioFormat.getBestMatch(source.getSupportedFormats(), ks.getSupportedFormats()); - this.sttFormat = AudioFormat.getBestMatch(source.getSupportedFormats(), stt.getSupportedFormats()); - this.ttsFormat = AudioFormat.getBestMatch(sink.getSupportedFormats(), tts.getSupportedFormats()); + this.ksFormat = VoiceManagerImpl.getBestMatch(source.getSupportedFormats(), ks.getSupportedFormats()); + this.sttFormat = VoiceManagerImpl.getBestMatch(source.getSupportedFormats(), stt.getSupportedFormats()); + this.ttsFormat = VoiceManagerImpl.getBestMatch(sink.getSupportedFormats(), tts.getSupportedFormats()); } public void start() { 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 07f96d8b90..cbf3284e85 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 @@ -231,7 +231,7 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider { throw new TTSException("Unable to find the audio sink " + sinkId); } - AudioFormat sttAudioFormat = AudioFormat.getBestMatch(sink.getSupportedFormats(), sttAudioFormats); + AudioFormat sttAudioFormat = getBestMatch(sink.getSupportedFormats(), sttAudioFormats); if (sttAudioFormat == null) { throw new TTSException("No compatible audio format found for TTS '" + tts.getId() + "' and sink '" + sink.getId() + "'"); @@ -426,6 +426,22 @@ 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