From 886a387632314a2d4315ed4599d56e4715d38d5d Mon Sep 17 00:00:00 2001 From: kratu92 Date: Tue, 14 Jun 2022 15:54:07 +0200 Subject: [PATCH] Moved ENABLE_INTERIM_RESULTS parameter from GoogleCloudTranscriptionService to RemotePublisherTranscriptionHandler --- README.md | 9 +++-- .../GoogleCloudTranscriptionService.java | 33 ++----------------- .../RemotePublisherTranscriptionHandler.java | 22 ++++++++++++- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index d5dc23b99..8d2bb10d2 100644 --- a/README.md +++ b/README.md @@ -131,11 +131,9 @@ By default, the properties `org.jitsi.jigasi.transcription.ENABLE_GOOGLE_AUTOMATIC_PUNCTUATION=false` and `org.jitsi.jigasi.transcription.ENABLE_GOOGLE_PROFANITY_FILTER=false` -and -`org.jitsi.jigasi.transcription.ENABLE_GOOGLE_INTERIM_RESULTS=false` in `jigasi-home/sip-communicator.properties` -disable automatic punctuation, profanity filter and interim results for the transcription. +disable automatic punctuation, profanity filter results for the transcription. To change this, simply set the desired property to `true` or `false`. Vosk configuration @@ -217,6 +215,11 @@ XMPP account must also be set to make Jigasi be able to join a conference room. in plain text. Note that this will result in the chat being somewhat spammed. + + org.jitsi.jigasi.transcription.ENABLE_INTERIM_RESULTS + false + Whether or not to send interim non-final results. Note that interim results should be handled so that no repeated transcriptions are displayed to the user. + Call control MUCs (brewery) diff --git a/src/main/java/org/jitsi/jigasi/transcription/GoogleCloudTranscriptionService.java b/src/main/java/org/jitsi/jigasi/transcription/GoogleCloudTranscriptionService.java index 7d1ef65b7..67bb28176 100644 --- a/src/main/java/org/jitsi/jigasi/transcription/GoogleCloudTranscriptionService.java +++ b/src/main/java/org/jitsi/jigasi/transcription/GoogleCloudTranscriptionService.java @@ -184,12 +184,6 @@ public class GoogleCloudTranscriptionService private final static String P_NAME_USE_VIDEO_MODEL = "org.jitsi.jigasi.transcription.USE_VIDEO_MODEL"; - /** - * Property name to determine whether to send the interim results - */ - private final static String P_NAME_ENABLE_GOOGLE_INTERIM_RESULTS - = "org.jitsi.jigasi.transcription.ENABLE_GOOGLE_INTERIM_RESULTS"; - /** * Property name to determine whether the Google Speech API should get * automatic punctuation @@ -209,11 +203,6 @@ public class GoogleCloudTranscriptionService */ private final static boolean DEFAULT_VALUE_USE_VIDEO_MODEL = false; - /** - * The default value for the property ENABLE_GOOGLE_INTERIM_RESULTS - */ - private final static boolean DEFAULT_VALUE_ENABLE_GOOGLE_INTERIM_RESULTS = false; - /** * The default value for the property ENABLE_GOOGLE_AUTOMATIC_PUNCTUATION */ @@ -259,11 +248,6 @@ private static void validateLanguageTag(String tag) */ private boolean useVideoModel; - /** - * Whether to send interim non-final results - */ - private boolean enableInterimResults; - /** * Whether to get automatic punctuation */ @@ -341,9 +325,6 @@ public GoogleCloudTranscriptionService() useVideoModel = JigasiBundleActivator.getConfigurationService() .getBoolean(P_NAME_USE_VIDEO_MODEL, DEFAULT_VALUE_USE_VIDEO_MODEL); - enableInterimResults = JigasiBundleActivator.getConfigurationService() - .getBoolean(P_NAME_ENABLE_GOOGLE_INTERIM_RESULTS, DEFAULT_VALUE_ENABLE_GOOGLE_INTERIM_RESULTS); - enableAutomaticPunctuation = JigasiBundleActivator.getConfigurationService() .getBoolean(P_NAME_ENABLE_GOOGLE_AUTOMATIC_PUNCTUATION, DEFAULT_VALUE_ENABLE_GOOGLE_AUTOMATIC_PUNCTUATION); @@ -745,8 +726,7 @@ private ApiStreamObserver createObserver( new ResponseApiStreamingObserver( this, config.getLanguageCode(), - debugName, - enableInterimResults); + debugName); // StreamingRecognitionConfig which will hold information // about the streaming session, including the RecognitionConfig @@ -927,11 +907,6 @@ private static class ResponseApiStreamingObserver */ private UUID messageID; - /** - * Whether to send interim results - */ - private Boolean enableInterimResults; - /** * Google provides multiple results per API response where the first one * contains the most stable part of the sentence and freshly transcribed @@ -951,13 +926,11 @@ private static class ResponseApiStreamingObserver */ ResponseApiStreamingObserver(RequestApiStreamObserverManager manager, String languageTag, - String debugName, - Boolean enableInterimResults) + String debugName) { this.requestManager = manager; this.languageTag = languageTag; this.debugName = debugName; - this.enableInterimResults = enableInterimResults; messageID = UUID.randomUUID(); } @@ -1091,7 +1064,7 @@ private void handleResult(StreamingRecognitionResult result) TranscriptionResult transcriptionResult = new TranscriptionResult( null, this.messageID, - !enableInterimResults && !result.getIsFinal(), + !result.getIsFinal(), this.languageTag, result.getStability(), new TranscriptionAlternative( diff --git a/src/main/java/org/jitsi/jigasi/transcription/RemotePublisherTranscriptionHandler.java b/src/main/java/org/jitsi/jigasi/transcription/RemotePublisherTranscriptionHandler.java index c8c975ac6..6a1f401e8 100644 --- a/src/main/java/org/jitsi/jigasi/transcription/RemotePublisherTranscriptionHandler.java +++ b/src/main/java/org/jitsi/jigasi/transcription/RemotePublisherTranscriptionHandler.java @@ -17,6 +17,7 @@ */ package org.jitsi.jigasi.transcription; +import org.jitsi.jigasi.*; import net.java.sip.communicator.service.protocol.*; import org.json.*; @@ -31,11 +32,27 @@ public class RemotePublisherTranscriptionHandler extends LocalJsonTranscriptHandler implements TranscriptionEventListener { + /** + * Property name to determine whether to send the interim results + */ + private final static String P_NAME_ENABLE_INTERIM_RESULTS + = "org.jitsi.jigasi.transcription.ENABLE_INTERIM_RESULTS"; + + /** + * The default value for the property ENABLE_INTERIM_RESULTS + */ + private final static boolean DEFAULT_VALUE_ENABLE_INTERIM_RESULTS = false; + /** * List of remote services to notify for transcriptions. */ private List urls = new ArrayList<>(); + /** + * Whether to send interim non-final results + */ + private boolean enableInterimResults; + /** * Constructs RemotePublisherTranscriptionHandler, initializing its config. * @@ -52,12 +69,15 @@ public RemotePublisherTranscriptionHandler(String urlsStr) { urls.add(tokens.nextToken().trim()); } + + enableInterimResults = JigasiBundleActivator.getConfigurationService() + .getBoolean(P_NAME_ENABLE_INTERIM_RESULTS, DEFAULT_VALUE_ENABLE_INTERIM_RESULTS); } @Override public void publish(ChatRoom room, TranscriptionResult result) { - if (result.isInterim()) + if (!enableInterimResults && result.isInterim()) return; JSONObject eventObject = createTranscriptionJSONObject(result);