From 93d46ebf07e248fddef35abf95fd9d7fb38d41aa Mon Sep 17 00:00:00 2001 From: hiroshisuga <45039819+hiroshisuga@users.noreply.github.com> Date: Wed, 14 Jun 2023 15:28:57 +0900 Subject: [PATCH 1/3] Update component.jsx --- .../ui/components/captions/pad/component.jsx | 75 +++++++++++++++++-- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/bigbluebutton-html5/imports/ui/components/captions/pad/component.jsx b/bigbluebutton-html5/imports/ui/components/captions/pad/component.jsx index dcfd99d928d2..c8f48ff3ab8d 100644 --- a/bigbluebutton-html5/imports/ui/components/captions/pad/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/captions/pad/component.jsx @@ -70,6 +70,9 @@ const DEBOUNCE_OPTIONS = { trailing: false, }; +const TIME_TO_EMIT_INTERIM = 3000; +const TIME_TO_STOP_INTERIM = 500; + class Pad extends PureComponent { static getDerivedStateFromProps(nextProps) { if (nextProps.ownerId !== nextProps.currentUserId) { @@ -101,6 +104,11 @@ class Pad extends PureComponent { } }); } + this.timeInt = Date.now(); + this.timePrevInt = Date.now(); + this.prevInterim = ''; + this.subsText = this.subsText.bind(this); + this.initialized = true; } componentDidMount() { @@ -138,6 +146,25 @@ class Pad extends PureComponent { this.setState({ url: PadService.buildPadURL(response) }); }); } + + subsText(textNew, textOld){ + console.log("subsText Old", textOld); + console.log("subsText New", textNew); + let subText = ""; + for (let i = 0; i < textOld.length; i += 1) { + if (textOld.charAt(i) != textNew.charAt(i)) { + //console.log("subsText i ", i); + subText = textNew.substr(i); + break; + } + } + if (subText == "") { + subText = textNew.substr(textOld.length); + } + console.log("subsText Sub", subText); + console.log(""); + return subText; + } handleListen() { const { @@ -180,8 +207,14 @@ class Pad extends PureComponent { // signaled by the isFinal flag. for (let i = resultIndex; i < results.length; i += 1) { const { transcript } = event.results[i][0]; - if (results[i].isFinal) finalTranscript += `${transcript} `; - else interimTranscript += transcript; + if (results[i].isFinal) { + finalTranscript += `${transcript} `; + //console.log('FINAL ' + i +' ' + transcript); + } else { interimTranscript += transcript; + //console.log('interim ' + i +' ' + transcript); + intervalInterim = Date.now() - this.timePrevInt; + this.timePrevInt = Date.now(); + } } // Adds the interimTranscript text to the iterimResultContainer to show @@ -190,13 +223,43 @@ class Pad extends PureComponent { this.iterimResultContainer.innerHTML = interimTranscript; } - const newEntry = finalTranscript !== ''; + if (this.initialized && (interimTranscript !== '' && this.prevInterim == '')) { + //if (this.initializable && interimTranscript.length < this.prevInterim.length) { + this.timeInt = Date.now(); + this.initialized = false; + } + + //const newEntry = finalTranscript !== ''; + //const newEntry = interimTranscript !== '' || finalTranscript !== ''; + let newEntry = false; + //const newEntry = finalTranscript !== '' || (interimTranscript !== '' && Date.now() - this.timeInt > TIME_TO_EMIT_INTERIM && interimTranscript != this.prevInterim); + if (finalTranscript !== '') { + newEntry = true; + } else if (interimTranscript !== '') { + console.log ("IntInterval", intervalInterim) ; + if (Date.now() - this.timeInt > TIME_TO_EMIT_INTERIM && interimTranscript != this.prevInterim && intervalInterim > TIME_TO_STOP_INTERIM) { + newEntry = true; + } + } // Changes to the finalTranscript are shown to in the captions if (newEntry) { - const text = finalTranscript.trimRight(); - CaptionsService.appendText(text, locale); - finalTranscript = ''; + let updateText = '' + if (finalTranscript !== '') { + updateText = this.subsText(finalTranscript, this.prevInterim); + this.prevInterim = ''; + this.initialized = true; + } else { + updateText = this.subsText(interimTranscript, this.prevInterim); + this.prevInterim = interimTranscript; + this.timeInt = Date.now(); + } + + //if (updateText !== '') { // can be the case when the interval between interim text updates is too short + const text = updateText.trimRight(); + CaptionsService.appendText(text, locale); + finalTranscript = ''; + //} } }; From 4fe810811ccf7e3ad22d872d97c8af8d5b1bf2c2 Mon Sep 17 00:00:00 2001 From: hiroshisuga <45039819+hiroshisuga@users.noreply.github.com> Date: Wed, 14 Jun 2023 21:35:52 +0900 Subject: [PATCH 2/3] Update component.jsx --- .../imports/ui/components/captions/pad/component.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bigbluebutton-html5/imports/ui/components/captions/pad/component.jsx b/bigbluebutton-html5/imports/ui/components/captions/pad/component.jsx index c8f48ff3ab8d..80c535c4d84f 100644 --- a/bigbluebutton-html5/imports/ui/components/captions/pad/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/captions/pad/component.jsx @@ -210,7 +210,8 @@ class Pad extends PureComponent { if (results[i].isFinal) { finalTranscript += `${transcript} `; //console.log('FINAL ' + i +' ' + transcript); - } else { interimTranscript += transcript; + } else { + interimTranscript += transcript; //console.log('interim ' + i +' ' + transcript); intervalInterim = Date.now() - this.timePrevInt; this.timePrevInt = Date.now(); From 2a5bc385740ee695fcaa5a0ecff15b9831e2ad5c Mon Sep 17 00:00:00 2001 From: hiroshisuga <45039819+hiroshisuga@users.noreply.github.com> Date: Thu, 15 Jun 2023 13:00:19 +0900 Subject: [PATCH 3/3] Update component.jsx --- .../imports/ui/components/captions/pad/component.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/bigbluebutton-html5/imports/ui/components/captions/pad/component.jsx b/bigbluebutton-html5/imports/ui/components/captions/pad/component.jsx index 80c535c4d84f..c83eb55af80f 100644 --- a/bigbluebutton-html5/imports/ui/components/captions/pad/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/captions/pad/component.jsx @@ -202,6 +202,7 @@ class Pad extends PureComponent { // Stores the first guess at what was recognised (Not always accurate). let interimTranscript = ''; + let intervalInterim = 0; // Loops through the results to check if any of the entries have been validated, // signaled by the isFinal flag.