@@ -225,19 +225,19 @@ public void say(String text, @Nullable String voiceId, @Nullable String sinkId,
225
225
throw new TTSException (
226
226
"Unable to find a voice for language " + localeProvider .getLocale ().getLanguage ());
227
227
}
228
- Set <AudioFormat > sttAudioFormats = tts .getSupportedFormats ();
228
+ Set <AudioFormat > ttsSupportedFormats = tts .getSupportedFormats ();
229
229
AudioSink sink = audioManager .getSink (sinkId );
230
230
if (sink == null ) {
231
231
throw new TTSException ("Unable to find the audio sink " + sinkId );
232
232
}
233
233
234
- AudioFormat sttAudioFormat = getBestMatch (sink .getSupportedFormats (), sttAudioFormats );
235
- if (sttAudioFormat == null ) {
234
+ AudioFormat ttsAudioFormat = getBestMatch (ttsSupportedFormats , sink .getSupportedFormats ());
235
+ if (ttsAudioFormat == null ) {
236
236
throw new TTSException ("No compatible audio format found for TTS '" + tts .getId () + "' and sink '"
237
237
+ sink .getId () + "'" );
238
238
}
239
239
240
- AudioStream audioStream = tts .synthesize (text , voice , sttAudioFormat );
240
+ AudioStream audioStream = tts .synthesize (text , voice , ttsAudioFormat );
241
241
if (!sink .getSupportedStreams ().stream ().anyMatch (clazz -> clazz .isInstance (audioStream ))) {
242
242
throw new TTSException (
243
243
"Failed playing audio stream '" + audioStream + "' as audio sink doesn't support it" );
@@ -503,8 +503,9 @@ public void startDialog(@Nullable KSService ks, @Nullable STTService stt, @Nulla
503
503
if (ksService == null || sttService == null || ttsService == null || interpreter == null || audioSource == null
504
504
|| audioSink == null || b == null ) {
505
505
throw new IllegalStateException ("Cannot start dialog as services are missing." );
506
- } else if (!ksService .getSupportedLocales ().contains (loc ) || !sttService .getSupportedLocales ().contains (loc )
507
- || !interpreter .getSupportedLocales ().contains (loc )) {
506
+ } else if (!checkLocales (ksService .getSupportedLocales (), loc )
507
+ || !checkLocales (sttService .getSupportedLocales (), loc )
508
+ || !checkLocales (interpreter .getSupportedLocales (), loc )) {
508
509
throw new IllegalStateException ("Cannot start dialog as provided locale is not supported by all services." );
509
510
} else {
510
511
DialogProcessor processor = dialogProcessors .get (audioSource .getId ());
@@ -548,6 +549,18 @@ private void stopAllDialogs() {
548
549
dialogProcessors .clear ();
549
550
}
550
551
552
+ private boolean checkLocales (@ Nullable Set <Locale > supportedLocales , Locale locale ) {
553
+ if (supportedLocales == null ) {
554
+ // rule interpreter returns null so allowing it
555
+ return true ;
556
+ }
557
+ return supportedLocales .stream ().anyMatch (sLocale -> {
558
+ var country = sLocale .getCountry ();
559
+ return Objects .equals (sLocale .getLanguage (), locale .getLanguage ())
560
+ && (country == null || country .isBlank () || country .equals (locale .getCountry ()));
561
+ });
562
+ }
563
+
551
564
@ Reference (cardinality = ReferenceCardinality .MULTIPLE , policy = ReferencePolicy .DYNAMIC )
552
565
protected void addKSService (KSService ksService ) {
553
566
this .ksServices .put (ksService .getId (), ksService );
0 commit comments