Skip to content

Commit

Permalink
fix: repeated strings in VOSK transcription results (#449)
Browse files Browse the repository at this point in the history
* fix: repeated strings in VOSK transcription results

* chore: add documentation

* chore: remove unrelated changes

* fix: send the final result, no matter what

Thanks for the review of @TomDurrant-yt
  • Loading branch information
charles-zablit committed Oct 3, 2022
1 parent 171e240 commit dda0721
Showing 1 changed file with 14 additions and 2 deletions.
Expand Up @@ -175,6 +175,12 @@ public class VoskWebsocketStreamingSession
*/
private final List<TranscriptionListener> listeners = new ArrayList<>();

/**
* Latest assigned UUID to a transcription result.
* A new one has to be generated whenever a definitive result is received.
*/
private UUID uuid = UUID.randomUUID();

VoskWebsocketStreamingSession(String debugName)
throws Exception
{
Expand Down Expand Up @@ -213,20 +219,26 @@ public void onMessage(String msg)
partial = false;
result = obj.getString("text");
}
if (!result.isEmpty() && !result.equals(lastResult))

if (!result.isEmpty() && (!partial || !result.equals(lastResult)))
{
lastResult = result;
for (TranscriptionListener l : listeners)
{
l.notify(new TranscriptionResult(
null,
UUID.randomUUID(),
this.uuid,
partial,
"C",
1.0,
new TranscriptionAlternative(result)));
}
}

if (!partial)
{
this.uuid = UUID.randomUUID();
}
}

@OnWebSocketError
Expand Down

0 comments on commit dda0721

Please sign in to comment.