mgbam commited on
Commit
085170e
·
verified ·
1 Parent(s): 2c90856

Update core/visual_engine.py

Browse files
Files changed (1) hide show
  1. core/visual_engine.py +35 -30
core/visual_engine.py CHANGED
@@ -470,7 +470,11 @@ class VisualEngine:
470
 
471
  # --- RunwayML Video Generation (Gen-4 Aligned with SDK) ---
472
  def _generate_video_clip_with_runwayml(
473
- self, text_prompt_for_motion, input_image_path, scene_identifier_filename_base, target_duration_seconds=5
 
 
 
 
474
  ):
475
  if not self.USE_RUNWAYML or not self.runway_ml_client_instance:
476
  logger.warning("RunwayML not enabled or client not initialized. Cannot generate video clip.")
@@ -589,8 +593,8 @@ class VisualEngine:
589
  # (Keeping as before)
590
  if size is None:
591
  size = self.video_frame_size
592
- fp = os.path.join(self.output_dir, filename)
593
- tc = None
594
  try:
595
  tc = TextClip(
596
  text_description,
@@ -781,6 +785,7 @@ class VisualEngine:
781
  try:
782
  logger.info(f"11L audio (Voice:{self.elevenlabs_voice_id}): {text_to_narrate[:70]}...")
783
  asm = None
 
784
  if hasattr(self.elevenlabs_client, "text_to_speech") and hasattr(
785
  self.elevenlabs_client.text_to_speech, "stream"
786
  ):
@@ -799,31 +804,33 @@ class VisualEngine:
799
  ab = self.elevenlabs_client.generate(
800
  text=text_to_narrate, voice=vp, model="eleven_multilingual_v2"
801
  )
802
- with open(afp, "wb") as f:
803
- f.write(ab)
804
- logger.info(f"11L audio (non-stream): {afp}")
805
- return afp
806
- else:
807
- logger.error("No 11L audio method.")
808
- return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
809
 
810
- if asm:
811
- vps = {"voice_id": str(self.elevenlabs_voice_id)}
812
- if self.elevenlabs_voice_settings:
813
- if hasattr(self.elevenlabs_voice_settings, "model_dump"):
814
- vps["voice_settings"] = self.elevenlabs_voice_settings.model_dump()
815
- elif hasattr(self.elevenlabs_voice_settings, "dict"):
816
- vps["voice_settings"] = self.elevenlabs_voice_settings.dict()
817
- else:
818
- vps["voice_settings"] = self.elevenlabs_voice_settings
819
-
820
- adi = asm(text=text_to_narrate, model_id="eleven_multilingual_v2", **vps)
821
- with open(afp, "wb") as f:
822
- for c in adi:
823
- if c:
824
- f.write(c)
825
- logger.info(f"11L audio (stream): {afp}")
826
- return afp
827
  except Exception as e:
828
  logger.error(f"11L audio error: {e}", exc_info=True)
829
  return None
@@ -1040,9 +1047,7 @@ class VisualEngine:
1040
  return None
1041
  finally:
1042
  logger.debug("Closing all MoviePy clips in `assemble_animatic_from_assets` finally block.")
1043
- all_clips_to_close = processed_clips + (
1044
- [narration_clip] if narration_clip else []
1045
- ) + ([final_clip] if final_clip else [])
1046
  for clip_obj_to_close in all_clips_to_close:
1047
  if clip_obj_to_close and hasattr(clip_obj_to_close, "close"):
1048
  try:
 
470
 
471
  # --- RunwayML Video Generation (Gen-4 Aligned with SDK) ---
472
  def _generate_video_clip_with_runwayml(
473
+ self,
474
+ text_prompt_for_motion,
475
+ input_image_path,
476
+ scene_identifier_filename_base,
477
+ target_duration_seconds=5,
478
  ):
479
  if not self.USE_RUNWAYML or not self.runway_ml_client_instance:
480
  logger.warning("RunwayML not enabled or client not initialized. Cannot generate video clip.")
 
593
  # (Keeping as before)
594
  if size is None:
595
  size = self.video_frame_size
596
+ fp = os.path.join(self.output_dir, filename)
597
+ tc = None
598
  try:
599
  tc = TextClip(
600
  text_description,
 
785
  try:
786
  logger.info(f"11L audio (Voice:{self.elevenlabs_voice_id}): {text_to_narrate[:70]}...")
787
  asm = None
788
+
789
  if hasattr(self.elevenlabs_client, "text_to_speech") and hasattr(
790
  self.elevenlabs_client.text_to_speech, "stream"
791
  ):
 
804
  ab = self.elevenlabs_client.generate(
805
  text=text_to_narrate, voice=vp, model="eleven_multilingual_v2"
806
  )
807
+ with open(afp, "wb") as f:
808
+ f.write(ab)
809
+ logger.info(f"11L audio (non-stream): {afp}")
810
+ return afp
811
+ else:
812
+ logger.error("No 11L audio method.")
813
+ return None
814
+
815
+ # If we have a streaming method (asm), use it
816
+ if asm:
817
+ vps = {"voice_id": str(self.elevenlabs_voice_id)}
818
+ if self.elevenlabs_voice_settings:
819
+ if hasattr(self.elevenlabs_voice_settings, "model_dump"):
820
+ vps["voice_settings"] = self.elevenlabs_voice_settings.model_dump()
821
+ elif hasattr(self.elevenlabs_voice_settings, "dict"):
822
+ vps["voice_settings"] = self.elevenlabs_voice_settings.dict()
823
+ else:
824
+ vps["voice_settings"] = self.elevenlabs_voice_settings
825
+
826
+ adi = asm(text=text_to_narrate, model_id="eleven_multilingual_v2", **vps)
827
+ with open(afp, "wb") as f:
828
+ for c in adi:
829
+ if c:
830
+ f.write(c)
831
+ logger.info(f"11L audio (stream): {afp}")
832
+ return afp
833
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
834
  except Exception as e:
835
  logger.error(f"11L audio error: {e}", exc_info=True)
836
  return None
 
1047
  return None
1048
  finally:
1049
  logger.debug("Closing all MoviePy clips in `assemble_animatic_from_assets` finally block.")
1050
+ all_clips_to_close = processed_clips + ([narration_clip] if narration_clip else []) + ([final_clip] if final_clip else [])
 
 
1051
  for clip_obj_to_close in all_clips_to_close:
1052
  if clip_obj_to_close and hasattr(clip_obj_to_close, "close"):
1053
  try: