diff --git a/demo/android/OrcaDemo/orca-demo-app/src/main/java/ai/picovoice/orcademo/MainActivity.java b/demo/android/OrcaDemo/orca-demo-app/src/main/java/ai/picovoice/orcademo/MainActivity.java index 3f9653c5..3a7ba47f 100644 --- a/demo/android/OrcaDemo/orca-demo-app/src/main/java/ai/picovoice/orcademo/MainActivity.java +++ b/demo/android/OrcaDemo/orca-demo-app/src/main/java/ai/picovoice/orcademo/MainActivity.java @@ -257,7 +257,7 @@ private void validateText(String text) { } else { Set invalidChars = new HashSet<>(); Matcher m = validationRegex.matcher(text); - while(m.find()) { + while (m.find()) { invalidChars.add(text.charAt(m.start())); } @@ -444,8 +444,11 @@ private void runStreamSynthesis(final String text) { CountDownLatch streamingAudioLatch = new CountDownLatch(1); executor.submit(() -> { + mainHandler.post(() -> { + streamTextView.setText(""); + }); + isStreamingText.set(true); - streamingSynthesisLatch.countDown(); String[] words = text.split(" "); for (String word : words) { @@ -455,6 +458,7 @@ private void runStreamSynthesis(final String text) { textStream.add(finalWord); streamTextView.append(finalWord); }); + streamingSynthesisLatch.countDown(); try { Thread.sleep(100); } catch (InterruptedException ignored) { } @@ -466,7 +470,6 @@ private void runStreamSynthesis(final String text) { executorStreamingSynthesis.submit(() -> { try { mainHandler.post(() -> { - streamTextView.setText(""); streamSecsTextView.setText("Seconds of audio synthesized: 0.000s"); synthesizeButton.setEnabled(false); }); @@ -537,7 +540,7 @@ private void runStreamSynthesis(final String text) { audioTrack.play(); streamingAudioLatch.await(); - while(isQueueingStreamingPcm.get() || !pcmQueue.isEmpty()) { + while (isQueueingStreamingPcm.get() || !pcmQueue.isEmpty()) { if (!pcmQueue.isEmpty()) { short[] pcm = pcmQueue.poll(); if (pcm != null && pcm.length > 0) { @@ -549,7 +552,10 @@ private void runStreamSynthesis(final String text) { audioTrack.stop(); audioTrack.release(); - mainHandler.post(() -> setUIState(UIState.EDIT)); + mainHandler.post(() -> { + setUIState(UIState.EDIT); + streamTextView.setText(""); + }); } catch (Exception e) { mainHandler.post(() -> displayError(e.toString())); }