Skip to content

Commit

Permalink
Merge pull request #832 from AI4Bharat/exportVOTR
Browse files Browse the repository at this point in the history
added votr active task export transcript and translation
  • Loading branch information
aparna-aa authored Oct 9, 2024
2 parents 80c14f0 + 33e6067 commit 083dbec
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 5 deletions.
22 changes: 18 additions & 4 deletions src/common/ExportDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import {
RadioGroup,
Typography,
FormGroup,
Select,
} from "@mui/material";
import CloseIcon from "@mui/icons-material/Close";
import { speakerInfoOptions, bgMusicOptions } from "config";
import { MenuItem } from "react-contextmenu";

const ExportDialog = ({
open,
Expand All @@ -32,11 +34,12 @@ const ExportDialog = ({
handleExportCheckboxChange,
isBulkTaskDownload,
currentSelectedTasks,
multiOptionDialog=false,
}) => {
const { transcription, translation, voiceover, speakerInfo, bgMusic } =
exportTypes;

const [currentTaskType, setCurrentTaskType] = useState("");
const [currentTaskType, setCurrentTaskType] = useState(taskType);

const transcriptExportTypes = useSelector(
(state) => state.getTranscriptExportTypes.data.export_types
Expand All @@ -58,7 +61,9 @@ const ExportDialog = ({
setCurrentTaskType("TRANSLATION_EDIT");
}
} else {
setCurrentTaskType(taskType);
if(!multiOptionDialog){
setCurrentTaskType(taskType);
}
}
}, [taskType, isBulkTaskDownload, currentSelectedTasks]);

Expand All @@ -69,7 +74,16 @@ const ExportDialog = ({
PaperProps={{ style: { borderRadius: "10px" } }}
>
<DialogTitle variant="h4" display="flex" alignItems={"center"}>
<Typography variant="h4">Export Voiceover</Typography>{" "}
{multiOptionDialog ?
<Typography variant="h4">Export &nbsp;
<Select value={currentTaskType} onChange={(event)=>{setCurrentTaskType(event.target.value)}}>
<MenuItem key={1} value="TRANSCRIPTION_VOICEOVER_EDIT">Transcription</MenuItem>
<MenuItem key={2} value="TRANSLATION_VOICEOVER_EDIT">Translation</MenuItem>
</Select>
</Typography>
:
<Typography variant="h4">Export {currentTaskType}</Typography>
}
<IconButton
aria-label="close"
onClick={handleClose}
Expand Down Expand Up @@ -201,7 +215,7 @@ const ExportDialog = ({
<DialogActions>
<Button
variant="contained"
onClick={handleExportSubmitClick}
onClick={multiOptionDialog ? () => handleExportSubmitClick(currentTaskType) : () => handleExportSubmitClick()}
style={{ borderRadius: "8px" }}
autoFocus
>
Expand Down
162 changes: 161 additions & 1 deletion src/containers/Organization/Video/VoiceOverRightPanel1.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import superscriptMap from "config/superscript";
import {
ConfirmDialog,
ConfirmErrorDialog,
ExportDialog,
RecorderComponent,
ShortcutKeys,
TableDialog,
Expand All @@ -58,10 +59,15 @@ import {
setTotalSentences,
setSnackBar,
CreateGlossaryAPI,
exportTranslationAPI,
FetchTranscriptExportTypesAPI,
FetchTranslationExportTypesAPI,
FetchVoiceoverExportTypesAPI,
exportTranscriptionAPI,
} from "redux/actions";
import { MenuItem } from "react-contextmenu";
import GlossaryDialog from "common/GlossaryDialog";
import { copySubs, onExpandTimeline } from "utils/subtitleUtils";
import { copySubs, exportFile, onExpandTimeline } from "utils/subtitleUtils";
import AudioPlayer from "./audioPanel";

const VoiceOverRightPanel1 = ({ currentIndex, setCurrentIndex, showTimeline, segment }) => {
Expand Down Expand Up @@ -130,13 +136,33 @@ const VoiceOverRightPanel1 = ({ currentIndex, setCurrentIndex, showTimeline, seg
const [redoStack, setRedoStack] = useState([]);
const [contextMenu, setContextMenu] = React.useState(null);
const [openGlossaryDialog, setOpenGlossaryDialog] = useState(false);
const [openExportDialog, setOpenExportDialog] = useState(false);
const [glossaryDialogTitle, setGlossaryDialogTitle] = useState(false);
const [selectedWord, setSelectedWord] = useState("");
const loggedInUserData = useSelector(
(state) => state.getLoggedInUserDetails.data
);
const [loader, setLoader] = useState(false);

const [exportTypes, setExportTypes] = useState({
transcription: ["srt"],
translation: ["srt"],
voiceover: "mp3",
speakerInfo: "false",
bgMusic: "false",
});

useEffect(() => {
const transcriptExportObj = new FetchTranscriptExportTypesAPI();
dispatch(APITransport(transcriptExportObj));

const translationExportObj = new FetchTranslationExportTypesAPI();
dispatch(APITransport(translationExportObj));

const voiceoverExportObj = new FetchVoiceoverExportTypesAPI();
dispatch(APITransport(voiceoverExportObj));
}, []);

useEffect(() => {
const { progress, success, data, apiType } = apiStatus;
setApiInProgress(progress);
Expand Down Expand Up @@ -744,6 +770,123 @@ const VoiceOverRightPanel1 = ({ currentIndex, setCurrentIndex, showTimeline, seg
// }, 60000);
// }, [currentOffset, sourceText]);

const handleTranscriptExport = async () => {
const { transcription, speakerInfo } = exportTypes;

transcription.map(async (transcript)=>{
const apiObj = new exportTranscriptionAPI(
taskId,
transcript,
speakerInfo
);
setOpenExportDialog(false);

try {
const res = await fetch(apiObj.apiEndPoint(), {
method: "GET",
headers: apiObj.getHeaders().headers,
});

if (res.ok) {
const resp = await res.blob();

exportFile(resp, taskData, transcript, "transcription");
} else {
const resp = await res.json();

dispatch(
setSnackBar({
open: true,
message: resp.message,
variant: "success",
})
);
}
} catch (error) {
dispatch(
setSnackBar({
open: true,
message: "Something went wrong!!",
variant: "error",
})
);
}})
};

const handleTranslationExport = async () => {
const { translation, speakerInfo } = exportTypes;

translation.map(async (translate)=>{
const apiObj = new exportTranslationAPI(taskId, translate, speakerInfo);
setOpenExportDialog(false);

try {
const res = await fetch(apiObj.apiEndPoint(), {
method: "GET",
headers: apiObj.getHeaders().headers,
});

if (res.ok) {
const resp = await res.blob();

exportFile(resp, taskData, translate, "translation");
} else {
const resp = await res.json();

dispatch(
setSnackBar({
open: true,
message: resp.message,
variant: "success",
})
);
}
} catch (error) {
dispatch(
setSnackBar({
open: true,
message: "Something went wrong!!",
variant: "error",
})
);
}})
};

const handleExportSubmitClick = (taskType) => {
if(taskType === "TRANSCRIPTION_VOICEOVER_EDIT"){
handleTranscriptExport();
}else{
handleTranslationExport();
}
};

const handleExportRadioButtonChange = (event) => {
const {
target: { name, value },
} = event;

setExportTypes((prevState) => ({
...prevState,
[name]: value,
}));
};

const handleExportCheckboxChange = (event) => {
const {
target: { name, value },
} = event;
let new_val=exportTypes[name]
if (new_val.includes(value)){
new_val = new_val.filter(item => item !== value)
} else{
new_val.push(value)
}
setExportTypes((prevState) => ({
...prevState,
[name]: new_val,
}));
}

return (
<>
{loader && <CircularProgress style={{position:"absolute", left:"50%", top:"50%", zIndex:"100"}} color="primary" size="50px" />}
Expand Down Expand Up @@ -781,6 +924,7 @@ const VoiceOverRightPanel1 = ({ currentIndex, setCurrentIndex, showTimeline, seg
handleReGenerateTranslation={()=>{changeTranscriptHandler(null, "retranslate", "retranslate")}}
handleGetUpdatedAudioForAll={()=>{changeTranscriptHandler(null, "audio", "audio")}}
bookmarkSegment={() => {saveTranscriptHandler(false, false, currentPage, true)}}
setOpenExportDialog={setOpenExportDialog}
/>
</Grid>

Expand Down Expand Up @@ -1156,6 +1300,22 @@ const VoiceOverRightPanel1 = ({ currentIndex, setCurrentIndex, showTimeline, seg
disableFields={true}
/>
)}

{openExportDialog && (
<ExportDialog
open={openExportDialog}
handleClose={() => setOpenExportDialog(false)}
task_type="TRANSLATION_VOICEOVER_EDIT"
taskType="TRANSLATION_VOICEOVER_EDIT"
exportTypes={exportTypes}
handleExportSubmitClick={handleExportSubmitClick}
handleExportRadioButtonChange={handleExportRadioButtonChange}
handleExportCheckboxChange={handleExportCheckboxChange}
isBulkTaskDownload={false}
currentSelectedTasks={[]}
multiOptionDialog={true}
/>
)}
</Box>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import LoopIcon from "@mui/icons-material/Loop";
import ExpandIcon from "@mui/icons-material/Expand";
import TaskAltIcon from "@mui/icons-material/TaskAlt";
import BookmarkIcon from '@mui/icons-material/BookmarkBorderOutlined';
import DownloadIcon from "@mui/icons-material/DownloadOutlined";

const anchorOrigin = {
vertical: "top",
Expand Down Expand Up @@ -80,6 +81,7 @@ const SettingsButtonComponent = ({
expandTimestamp,
handleGetUpdatedAudioForAll,
bookmarkSegment,
setOpenExportDialog,
}) => {
const classes = VideoLandingStyle();

Expand Down Expand Up @@ -521,6 +523,22 @@ const SettingsButtonComponent = ({
targetLanguage={taskData?.target_language}
/>
)}

{taskData?.task_type?.includes("TRANSLATION_VOICEOVER") &&
<>
<Divider orientation="vertical" className={classes.rightPanelDivider} />

<Tooltip title="Export" placement="bottom">
<IconButton
className={classes.rightPanelBtnGrp}
onClick={() => {setOpenExportDialog(true)}}
>
<DownloadIcon className={classes.rightPanelSvg} />
</IconButton>
</Tooltip>

</>
}
</>
);
};
Expand Down

0 comments on commit 083dbec

Please sign in to comment.