diff --git a/backend/src/bundles/avatar-videos/services/script-processor.service.ts b/backend/src/bundles/avatar-videos/services/script-processor.service.ts index 16344051e..26fe4df59 100644 --- a/backend/src/bundles/avatar-videos/services/script-processor.service.ts +++ b/backend/src/bundles/avatar-videos/services/script-processor.service.ts @@ -73,7 +73,22 @@ class ScriptProcessor { voice: string; scene: Scene; }): void { - if (text && this.currentAvatar) { + if (!text || !this.currentAvatar) { + return; + } + + const lastScene = this.result.at(-1); + + if ( + lastScene && + lastScene.avatar.voice === voice && + lastScene.avatar.name === this.currentAvatar.name && + lastScene.avatar.style === this.currentAvatar.style && + JSON.stringify(lastScene.background) === + JSON.stringify(scene.background) + ) { + lastScene.avatar.text += ' ' + text; + } else { this.result.push({ ...scene, id: uuidv4(), diff --git a/frontend/src/bundles/studio/helpers/are-all-scenes-with-scenes.helper.ts b/frontend/src/bundles/studio/helpers/are-all-scenes-with-scenes.helper.ts new file mode 100644 index 000000000..60271a87e --- /dev/null +++ b/frontend/src/bundles/studio/helpers/are-all-scenes-with-scenes.helper.ts @@ -0,0 +1,7 @@ +import { type Scene } from '../types/types.js'; + +function areAllScenesWithAvatar(scenes: Scene[]): boolean { + return scenes.every((scene) => scene.avatar !== undefined); +} + +export { areAllScenesWithAvatar }; diff --git a/frontend/src/bundles/studio/helpers/helpers.ts b/frontend/src/bundles/studio/helpers/helpers.ts index 00ac68474..7a14da2ba 100644 --- a/frontend/src/bundles/studio/helpers/helpers.ts +++ b/frontend/src/bundles/studio/helpers/helpers.ts @@ -1,5 +1,6 @@ export { addScene } from './add-scene.js'; export { addScript } from './add-script.js'; +export { areAllScenesWithAvatar } from './are-all-scenes-with-scenes.helper.js'; export { createDefaultAvatarFromRequest } from './create-default-avatar.js'; export { getDestinationPointerValue } from './get-destination-pointer-value.js'; export { getElementEnd } from './get-element-end.js'; diff --git a/frontend/src/bundles/studio/pages/studio.tsx b/frontend/src/bundles/studio/pages/studio.tsx index 112d30abe..837916138 100644 --- a/frontend/src/bundles/studio/pages/studio.tsx +++ b/frontend/src/bundles/studio/pages/studio.tsx @@ -46,7 +46,11 @@ import { VIDEO_SUBMIT_NOTIFICATION_ID, } from '../constants/constants.js'; import { NotificationMessage, NotificationTitle } from '../enums/enums.js'; -import { getVoicesConfigs, scenesExceedScripts } from '../helpers/helpers.js'; +import { + areAllScenesWithAvatar, + getVoicesConfigs, + scenesExceedScripts, +} from '../helpers/helpers.js'; import { selectVideoDataById } from '../store/selectors.js'; import { actions as studioActions } from '../store/studio.js'; @@ -93,15 +97,14 @@ const Studio: React.FC = () => { const handleConfirmSubmit = useCallback(() => { // TODO: REPLACE LOGIC WITH MULTIPLE SCENES - const scene = scenes[0]; + const script = scripts[0]; - if (!scene?.avatar || !script) { - notificationService.warn({ + if (!areAllScenesWithAvatar(scenes) || !script) { + return notificationService.warn({ id: SCRIPT_AND_AVATAR_ARE_REQUIRED, message: NotificationMessage.SCRIPT_AND_AVATAR_ARE_REQUIRED, title: NotificationTitle.SCRIPT_AND_AVATAR_ARE_REQUIRED, }); - return; } void dispatch(studioActions.generateAllScriptsSpeech()) @@ -158,7 +161,6 @@ const Studio: React.FC = () => { composition: { scenes, scripts: getVoicesConfigs(scripts), - // TODO : CHANGE TO ENUM videoOrientation: videoSize, }, name: videoName,