From: GiviMAD Date: Fri, 24 Mar 2023 23:20:34 +0000 (+0100) Subject: [rustpotterks] Remove unnecessary thread sleep call (#14664) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=c30893281cdca8ae626f6cb726b652a71f74a012;p=openhab-addons.git [rustpotterks] Remove unnecessary thread sleep call (#14664) * [rustpotterks] Remove unnecessary thread sleep call Signed-off-by: Miguel Álvarez --- diff --git a/bundles/org.openhab.voice.rustpotterks/src/main/java/org/openhab/voice/rustpotterks/internal/RustpotterKSService.java b/bundles/org.openhab.voice.rustpotterks/src/main/java/org/openhab/voice/rustpotterks/internal/RustpotterKSService.java index c31982e508..e6f4f8ada9 100644 --- a/bundles/org.openhab.voice.rustpotterks/src/main/java/org/openhab/voice/rustpotterks/internal/RustpotterKSService.java +++ b/bundles/org.openhab.voice.rustpotterks/src/main/java/org/openhab/voice/rustpotterks/internal/RustpotterKSService.java @@ -191,12 +191,11 @@ public class RustpotterKSService implements KSService { while (!aborted.get()) { try { numBytesRead = audioStream.read(audioBuffer, bufferSize - remaining, remaining); - if (aborted.get()) { + if (aborted.get() || numBytesRead == -1) { break; } if (numBytesRead != remaining) { remaining = remaining - numBytesRead; - Thread.sleep(100); continue; } remaining = bufferSize; @@ -217,7 +216,7 @@ public class RustpotterKSService implements KSService { detection.delete(); ksListener.ksEventReceived(new KSpottedEvent()); } - } catch (IOException | InterruptedException e) { + } catch (IOException e) { String errorMessage = e.getMessage(); ksListener.ksEventReceived(new KSErrorEvent(errorMessage != null ? errorMessage : "Unexpected error")); }