diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/AudioStartEvent.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/AudioStartEvent.java index e379f1ce28..6171536771 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/AudioStartEvent.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/AudioStartEvent.java @@ -12,10 +12,13 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * A {@link STTEvent} fired when the {@link STTService} starts hearing audio. * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class AudioStartEvent implements STTEvent { } diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/AudioStopEvent.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/AudioStopEvent.java index b053d7a985..835b173f8c 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/AudioStopEvent.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/AudioStopEvent.java @@ -12,10 +12,13 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * A {@link STTEvent} fired when the {@link STTService} stops hearing audio. * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class AudioStopEvent implements STTEvent { } diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSErrorEvent.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSErrorEvent.java index 4f4b65ebff..6448843d28 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSErrorEvent.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSErrorEvent.java @@ -12,11 +12,14 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * A {@link KSEvent} fired when the {@link KSService} encounters an error. * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class KSErrorEvent implements KSEvent { /** * The message describing the error diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSEvent.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSEvent.java index 937313a3fa..2757ccef36 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSEvent.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSEvent.java @@ -12,10 +12,13 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * A tagging interface for keyword spotting events. * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public interface KSEvent { } diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSException.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSException.java index ed484ffff6..6289297699 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSException.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSException.java @@ -12,11 +12,14 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * General purpose keyword spotting exception * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class KSException extends Exception { private static final long serialVersionUID = 1L; diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSListener.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSListener.java index 239f70b5ec..ba5534fe36 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSListener.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSListener.java @@ -12,6 +12,8 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * The listener interface for receiving {@link KSEvent} events. * @@ -22,6 +24,7 @@ package org.openhab.core.voice; * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public interface KSListener { /** * Invoked when a {@link KSEvent} event occurs during keyword spotting. diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSService.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSService.java index 3fb2cb3831..697c9a3103 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSService.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSService.java @@ -15,6 +15,8 @@ package org.openhab.core.voice; import java.util.Locale; import java.util.Set; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioStream; @@ -24,6 +26,7 @@ import org.openhab.core.audio.AudioStream; * @author Kelly Davis - Initial contribution * @author Kai Kreuzer - Refactored to use AudioStream */ +@NonNullByDefault public interface KSService { /** @@ -39,7 +42,7 @@ public interface KSService { * @param locale the locale to provide the label for * @return a localized string to be used in UIs */ - public String getLabel(Locale locale); + public String getLabel(@Nullable Locale locale); /** * Obtain the Locales available from this KSService diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSServiceHandle.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSServiceHandle.java index 0513e4e025..d641e3ff63 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSServiceHandle.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSServiceHandle.java @@ -12,11 +12,14 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * An handle to a {@link KSService} * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public interface KSServiceHandle { /** * Aborts keyword spotting in the associated {@link KSService} diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSpottedEvent.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSpottedEvent.java index ed939a3013..94d6497770 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSpottedEvent.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSpottedEvent.java @@ -12,11 +12,14 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * A {@link KSEvent} fired when the {@link KSService} spots a keyword. * * @author Kelly Davis - Initial contribution * @author Yannick Schaus - Removed AudioSource information */ +@NonNullByDefault public class KSpottedEvent implements KSEvent { } diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/RecognitionStartEvent.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/RecognitionStartEvent.java index 05d5563251..6180893107 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/RecognitionStartEvent.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/RecognitionStartEvent.java @@ -12,10 +12,13 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * A {@link STTEvent} fired when the {@link STTService} starts recognition. * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class RecognitionStartEvent implements STTEvent { } diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/RecognitionStopEvent.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/RecognitionStopEvent.java index 6f75fcfcb3..2fb2ecac66 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/RecognitionStopEvent.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/RecognitionStopEvent.java @@ -12,10 +12,13 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * A {@link STTEvent} fired when the {@link STTService} stops recognition. * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class RecognitionStopEvent implements STTEvent { } diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTEvent.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTEvent.java index 783f4d2868..7c444dfcf5 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTEvent.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTEvent.java @@ -12,10 +12,13 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * A tagging interface for speech-to-text events. * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public interface STTEvent { } diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTException.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTException.java index d0e7510ece..a5b8a26fec 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTException.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTException.java @@ -12,11 +12,14 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * General purpose STT exception * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class STTException extends Exception { private static final long serialVersionUID = 1L; diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTListener.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTListener.java index 9df1076afc..217024fca9 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTListener.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTListener.java @@ -12,6 +12,8 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * The listener interface for receiving {@link STTEvent} events. * @@ -22,6 +24,7 @@ package org.openhab.core.voice; * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public interface STTListener { /** diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTService.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTService.java index e7ff736614..e4346d9d9e 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTService.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTService.java @@ -15,6 +15,8 @@ package org.openhab.core.voice; import java.util.Locale; import java.util.Set; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioStream; @@ -23,6 +25,7 @@ import org.openhab.core.audio.AudioStream; * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public interface STTService { /** @@ -38,7 +41,7 @@ public interface STTService { * @param locale the locale to provide the label for * @return a localized string to be used in UIs */ - public String getLabel(Locale locale); + public String getLabel(@Nullable Locale locale); /** * Obtain the Locales available from this STTService diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTServiceHandle.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTServiceHandle.java index 3c5f39481d..e8b990b672 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTServiceHandle.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTServiceHandle.java @@ -12,11 +12,14 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * An handle to a {@link STTService} * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public interface STTServiceHandle { /** * Aborts recognition in the associated {@link STTService} diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechRecognitionErrorEvent.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechRecognitionErrorEvent.java index d728613d6f..5ab6af1440 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechRecognitionErrorEvent.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechRecognitionErrorEvent.java @@ -12,11 +12,14 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * A {@link STTEvent} fired when the {@link STTService} encounters an error. * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class SpeechRecognitionErrorEvent implements STTEvent { /** * The message describing the error diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechRecognitionEvent.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechRecognitionEvent.java index 7af576b771..85a3db6c10 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechRecognitionEvent.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechRecognitionEvent.java @@ -12,11 +12,14 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * A {@link STTEvent} fired when the {@link STTService} recognizes speech. * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class SpeechRecognitionEvent implements STTEvent { /** * Confidence of recognized speech diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechStartEvent.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechStartEvent.java index 1dc6703e9e..988c1ee12e 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechStartEvent.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechStartEvent.java @@ -12,10 +12,13 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * A {@link STTEvent} fired when the {@link STTService} starts hearing speech. * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class SpeechStartEvent implements STTEvent { } diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechStopEvent.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechStopEvent.java index e858484436..d76cbe6d99 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechStopEvent.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/SpeechStopEvent.java @@ -12,10 +12,13 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * A {@link STTEvent} fired when the {@link STTService} stops hearing speech. * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class SpeechStopEvent implements STTEvent { } diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/TTSException.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/TTSException.java index e4b66e4d29..39830e0cc8 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/TTSException.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/TTSException.java @@ -12,11 +12,14 @@ */ package org.openhab.core.voice; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * General purpose TTS exception * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class TTSException extends Exception { private static final long serialVersionUID = 1L; diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/TTSService.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/TTSService.java index 17949deb95..c80b86e773 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/TTSService.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/TTSService.java @@ -15,6 +15,8 @@ package org.openhab.core.voice; import java.util.Locale; import java.util.Set; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioStream; @@ -24,6 +26,7 @@ import org.openhab.core.audio.AudioStream; * @author Kelly Davis - Initial contribution * @author Kai Kreuzer - Refactored to use AudioStreams */ +@NonNullByDefault public interface TTSService { /** @@ -39,7 +42,7 @@ public interface TTSService { * @param locale the locale to provide the label for * @return a localized string to be used in UIs */ - public String getLabel(Locale locale); + public String getLabel(@Nullable Locale locale); /** * Obtain the voices available from this TTSService diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/Voice.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/Voice.java index 89cf198f0b..0d8bf72ad2 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/Voice.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/Voice.java @@ -14,11 +14,14 @@ package org.openhab.core.voice; import java.util.Locale; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * This is the interface that a text-to-speech voice has to implement. * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public interface Voice { /** 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 3de1d6541c..4a624784d3 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,8 +12,11 @@ */ package org.openhab.core.voice.internal; +import static org.openhab.core.voice.internal.VoiceManagerImpl.getBestMatch; + import java.util.HashSet; import java.util.Locale; +import java.util.Set; import org.openhab.core.audio.AudioException; import org.openhab.core.audio.AudioFormat; @@ -104,7 +107,7 @@ public class DialogProcessor implements KSListener, STTListener { public void start() { try { - ks.spot(this, source.getInputStream(format), locale, this.keyword); + ks.spot(this, source.getInputStream(format), locale, keyword); } catch (KSException e) { logger.error("Encountered error calling spot: {}", e.getMessage()); } catch (AudioException e) { @@ -113,10 +116,10 @@ public class DialogProcessor implements KSListener, STTListener { } private void toggleProcessing(boolean value) { - if (this.processing == value) { + if (processing == value) { return; } - this.processing = value; + processing = value; if (listeningItem != null && ItemUtil.isValidItemName(listeningItem)) { OnOffType command = (value) ? OnOffType.ON : OnOffType.OFF; eventPublisher.post(ItemEventFactory.createCommandEvent(listeningItem, command)); @@ -126,13 +129,12 @@ public class DialogProcessor implements KSListener, STTListener { @Override public void ksEventReceived(KSEvent ksEvent) { if (!processing) { - this.isSTTServerAborting = false; + isSTTServerAborting = false; if (ksEvent instanceof KSpottedEvent) { toggleProcessing(true); if (stt != null) { try { - this.sttServiceHandle = stt.recognize(this, source.getInputStream(format), this.locale, - new HashSet<>()); + sttServiceHandle = stt.recognize(this, source.getInputStream(format), locale, new HashSet<>()); } catch (STTException e) { say("Error during recognition: " + e.getMessage()); } catch (AudioException e) { @@ -149,14 +151,14 @@ public class DialogProcessor implements KSListener, STTListener { @Override public synchronized void sttEventReceived(STTEvent sttEvent) { if (sttEvent instanceof SpeechRecognitionEvent) { - if (!this.isSTTServerAborting) { - this.sttServiceHandle.abort(); - this.isSTTServerAborting = true; + if (!isSTTServerAborting) { + sttServiceHandle.abort(); + isSTTServerAborting = true; SpeechRecognitionEvent sre = (SpeechRecognitionEvent) sttEvent; String question = sre.getTranscript(); try { toggleProcessing(false); - String answer = hli.interpret(this.locale, question); + String answer = hli.interpret(locale, question); if (answer != null) { say(answer); } @@ -167,9 +169,9 @@ public class DialogProcessor implements KSListener, STTListener { } else if (sttEvent instanceof RecognitionStopEvent) { toggleProcessing(false); } else if (sttEvent instanceof SpeechRecognitionErrorEvent) { - if (!this.isSTTServerAborting) { - this.sttServiceHandle.abort(); - this.isSTTServerAborting = true; + if (!isSTTServerAborting) { + sttServiceHandle.abort(); + isSTTServerAborting = true; toggleProcessing(false); SpeechRecognitionErrorEvent sre = (SpeechRecognitionErrorEvent) sttEvent; say("Encountered error: " + sre.getMessage()); @@ -186,15 +188,23 @@ public class DialogProcessor implements KSListener, STTListener { try { Voice voice = null; for (Voice currentVoice : tts.getAvailableVoices()) { - if (this.locale.getLanguage().equals(currentVoice.getLocale().getLanguage())) { + if (locale.getLanguage().equals(currentVoice.getLocale().getLanguage())) { voice = currentVoice; break; } } - if (null == voice) { + if (voice == null) { throw new TTSException("Unable to find a suitable voice"); } - AudioStream audioStream = tts.synthesize(text, voice, null); + + Set audioFormats = tts.getSupportedFormats(); + AudioFormat audioFormat = getBestMatch(audioFormats, sink.getSupportedFormats()); + if (audioFormat == null) { + throw new TTSException("No compatible audio format found for TTS '" + tts.getId() + "' and sink '" + + sink.getId() + "'"); + } + + AudioStream audioStream = tts.synthesize(text, voice, audioFormat); if (sink.getSupportedStreams().stream().anyMatch(clazz -> clazz.isInstance(audioStream))) { try { diff --git a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/STTExceptionTest.java b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/STTExceptionTest.java index 9c53f1f06f..086e897bba 100644 --- a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/STTExceptionTest.java +++ b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/STTExceptionTest.java @@ -14,6 +14,7 @@ package org.openhab.core.voice; import static org.junit.jupiter.api.Assertions.assertNotNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; /** @@ -21,6 +22,7 @@ import org.junit.jupiter.api.Test; * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class STTExceptionTest { /** diff --git a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionErrorEventTest.java b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionErrorEventTest.java index 7e884d7183..d34c52afb7 100644 --- a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionErrorEventTest.java +++ b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionErrorEventTest.java @@ -14,6 +14,7 @@ package org.openhab.core.voice; import static org.junit.jupiter.api.Assertions.*; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; /** @@ -21,6 +22,7 @@ import org.junit.jupiter.api.Test; * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class SpeechRecognitionErrorEventTest { /** diff --git a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionEventTest.java b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionEventTest.java index 0351cc785e..e28dd57f17 100644 --- a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionEventTest.java +++ b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionEventTest.java @@ -14,6 +14,7 @@ package org.openhab.core.voice; import static org.junit.jupiter.api.Assertions.*; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; /** @@ -21,6 +22,7 @@ import org.junit.jupiter.api.Test; * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class SpeechRecognitionEventTest { /** diff --git a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/TTSExceptionTest.java b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/TTSExceptionTest.java index e2d6afb458..61f547154d 100644 --- a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/TTSExceptionTest.java +++ b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/TTSExceptionTest.java @@ -14,6 +14,7 @@ package org.openhab.core.voice; import static org.junit.jupiter.api.Assertions.assertNotNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; /** @@ -21,6 +22,7 @@ import org.junit.jupiter.api.Test; * * @author Kelly Davis - Initial contribution */ +@NonNullByDefault public class TTSExceptionTest { /** diff --git a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/KSServiceStub.java b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/KSServiceStub.java index f6dd6ae436..02709cbd49 100644 --- a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/KSServiceStub.java +++ b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/KSServiceStub.java @@ -54,7 +54,7 @@ public class KSServiceStub implements KSService { @Override public Set getSupportedLocales() { - return null; + return Set.of(); } @Override diff --git a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/STTServiceStub.java b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/STTServiceStub.java index 7027223156..4a60d4a841 100644 --- a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/STTServiceStub.java +++ b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/STTServiceStub.java @@ -15,6 +15,8 @@ package org.openhab.core.voice.internal; import java.util.Locale; import java.util.Set; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioStream; import org.openhab.core.voice.STTException; @@ -28,6 +30,7 @@ import org.openhab.core.voice.STTServiceHandle; * @author Mihaela Memova - Initial contribution * @author Velin Yordanov - migrated from groovy to java */ +@NonNullByDefault public class STTServiceStub implements STTService { private static final Set SUPPORTED_FORMATS = Set.of(AudioFormat.MP3, AudioFormat.WAV); @@ -41,13 +44,13 @@ public class STTServiceStub implements STTService { } @Override - public String getLabel(Locale locale) { + public String getLabel(@Nullable Locale locale) { return STTSERVICE_STUB_LABEL; } @Override public Set getSupportedLocales() { - return null; + return Set.of(); } @Override diff --git a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/TTSServiceStub.java b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/TTSServiceStub.java index b0a184d243..0142bb7788 100644 --- a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/TTSServiceStub.java +++ b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/TTSServiceStub.java @@ -14,10 +14,12 @@ package org.openhab.core.voice.internal; import java.io.IOException; import java.util.Collection; -import java.util.HashSet; import java.util.Locale; import java.util.Set; +import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioStream; import org.openhab.core.voice.TTSException; @@ -33,6 +35,7 @@ import org.osgi.framework.ServiceReference; * @author Mihaela Memova - Initial contribution * @author Velin Yordanov - migrated from groovy to java */ +@NonNullByDefault public class TTSServiceStub implements TTSService { private static final Set SUPPORTED_FORMATS = Set.of(AudioFormat.MP3, AudioFormat.WAV); @@ -40,45 +43,42 @@ public class TTSServiceStub implements TTSService { private static final String TTS_SERVICE_STUB_ID = "ttsServiceStubID"; private static final String TTS_SERVICE_STUB_LABEL = "ttsServiceStubLabel"; - private Set availableVoices; - private BundleContext context; + private @Nullable BundleContext context; + + public TTSServiceStub() { + } public TTSServiceStub(BundleContext context) { this.context = context; } - public TTSServiceStub() { - } - @Override public String getId() { return TTS_SERVICE_STUB_ID; } @Override - public String getLabel(Locale locale) { + public String getLabel(@Nullable Locale locale) { return TTS_SERVICE_STUB_LABEL; } @Override public Set getAvailableVoices() { - availableVoices = new HashSet<>(); - Collection> refs; + BundleContext bundleContext = this.context; + if (bundleContext == null) { + return Set.of(); + } + try { - refs = context.getServiceReferences(Voice.class, null); - if (refs != null) { - for (ServiceReference ref : refs) { - Voice service = context.getService(ref); - if (service.getUID().startsWith(getId())) { - availableVoices.add(service); - } - } - } + Collection> refs = bundleContext.getServiceReferences(Voice.class, null); + return refs.stream() // + .map(ref -> bundleContext.getService(ref)) // + .filter(service -> service.getUID().startsWith(getId())) // + .collect(Collectors.toSet()); } catch (InvalidSyntaxException e) { // If the specified filter contains an invalid filter expression that cannot be parsed. - return null; + return Set.of(); } - return availableVoices; } @Override diff --git a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/VoiceStub.java b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/VoiceStub.java index aa5f0c3c4d..a5cd22a5a0 100644 --- a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/VoiceStub.java +++ b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/VoiceStub.java @@ -14,6 +14,7 @@ package org.openhab.core.voice.internal; import java.util.Locale; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.voice.Voice; /** @@ -22,6 +23,7 @@ import org.openhab.core.voice.Voice; * @author Mihaela Memova - Initial contribution * @author Velin Yordanov - migrated from groovy to java */ +@NonNullByDefault public class VoiceStub implements Voice { private TTSServiceStub ttsService = new TTSServiceStub();