[Voice] restore getBestMatch method (#2802)

Signed-off-by: Miguel Álvarez Díez <miguelwork92@gmail.com>
pull/2804/head
GiviMAD 2022-02-26 09:32:06 +01:00 committed by GitHub
parent 7c3f49ab42
commit b57a8c3beb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -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() {

View File

@ -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<AudioFormat> inputs, Set<AudioFormat> 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<Voice> voices) {
// Express preferences with a Language Priority List