Skip to content

Commit

Permalink
Dubbing: Refine window and ASR. v5.15.21
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jul 23, 2024
1 parent a21cac0 commit 369c53c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions ui/src/pages/ScenarioDubbing.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,14 +651,14 @@ function DubbingUISubtitles({task, playerRef, isFullscreen, showHeader, showASR,
const {t} = useTranslation();

// How many groups to show when in the fullscreen.
const [historyGroups, setHistoryGroups] = React.useState(3);
const [historySegments, setHistorySegments] = React.useState(4);
React.useEffect(() => {
let v = 4;
if (!showHeader) v += 2;
if (!showASR) v += 3;
if (!showTranslation) v += 3;
setHistoryGroups(v);
}, [showHeader, showASR, showTranslation, setHistoryGroups]);
setHistorySegments(v);
}, [showHeader, showASR, showTranslation, setHistorySegments]);

const selectVariant = (index, g) => {
if (g.free_space !== undefined) {
Expand Down Expand Up @@ -695,15 +695,21 @@ function DubbingUISubtitles({task, playerRef, isFullscreen, showHeader, showASR,
return s.start <= playerRef.current.currentTime && playerRef.current.currentTime <= s.end;
});
if (index === -1) return;
index = Math.max(0, index - historyGroups);

let availableSegments = historySegments;
for (let i = index - 1; i >= 0 && availableSegments > 0; i--) {
availableSegments -= task?.asr_response?.groups[i]?.segments?.length;
if (availableSegments >= 0) index--;
}
index = Math.max(0, index);

const divId = `asr-group-${index}`;
const target = document.querySelector(`div#${divId}`);
if (target) target.scrollIntoView({behavior: 'smooth'});
//console.log(`Locate group ${index}, div ${divId}, time ${playerRef.current.currentTime}, group is ${group?.id}, ${group?.start} ~ ${group?.end}`);
}, 800);
return () => clearInterval(timer);
}, [playerRef, task, isPlayingAudio, isFullscreen, historyGroups]);
}, [playerRef, task, isPlayingAudio, isFullscreen, historySegments]);

return <>
{task?.asr_response?.groups?.map((g, index) => {
Expand Down

0 comments on commit 369c53c

Please sign in to comment.