Narayana02 commited on
Commit
05a01a3
·
verified ·
1 Parent(s): 93f0322

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +26 -0
utils.py CHANGED
@@ -9,6 +9,7 @@ import tempfile
9
  from gtts import gTTS
10
  from bs4 import BeautifulSoup
11
  import requests
 
12
 
13
  # Initialize Groq client and tokenizer
14
  groq_client = Groq(api_key=os.environ["GROQ_API_KEY"])
@@ -107,3 +108,28 @@ def generate_audio(text: str, speaker: str) -> str:
107
  return temp_audio.name
108
  except Exception as e:
109
  raise RuntimeError(f"Error generating audio: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  from gtts import gTTS
10
  from bs4 import BeautifulSoup
11
  import requests
12
+ from moviepy.editor import ImageClip, AudioFileClip
13
 
14
  # Initialize Groq client and tokenizer
15
  groq_client = Groq(api_key=os.environ["GROQ_API_KEY"])
 
108
  return temp_audio.name
109
  except Exception as e:
110
  raise RuntimeError(f"Error generating audio: {str(e)}")
111
+
112
+ # Generate video using audio and image
113
+ def generate_video(audio_path: str, image_path: str) -> str:
114
+ """
115
+ Combines an audio file and an image to generate a video.
116
+
117
+ Args:
118
+ audio_path (str): Path to the audio file.
119
+ image_path (str): Path to the image file.
120
+
121
+ Returns:
122
+ str: Path to the generated video file.
123
+ """
124
+ try:
125
+ audio = AudioFileClip(audio_path)
126
+ video = ImageClip(image_path, duration=audio.duration)
127
+ video = video.set_audio(audio)
128
+
129
+ # Define the output path
130
+ output_path = tempfile.mktemp(suffix=".mp4")
131
+ video.write_videofile(output_path, codec="libx264", audio_codec="aac")
132
+
133
+ return output_path
134
+ except Exception as e:
135
+ raise RuntimeError(f"Error generating video: {str(e)}")