muruga778 commited on
Commit
04590b0
·
verified ·
1 Parent(s): 523daea

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import whisper
3
+ from TTS.api import TTS
4
+ import os
5
+ import tempfile
6
+ import numpy as np
7
+ from moviepy.editor import *
8
+
9
+ def clone_voice(text, reference_audio_path):
10
+ # Initialize Coqui TTS with a voice cloning model
11
+ tts = TTS(model_name="tts_models/multilingual/multi-dataset/your_tts", progress_bar=False)
12
+
13
+ # Generate speech with cloned voice
14
+ output_path = "cloned_voice.wav"
15
+ tts.tts_to_file(text=text, speaker_wav=reference_audio_path, language="en", file_path=output_path)
16
+
17
+ return output_path
18
+
19
+ def generate_video_resume(resume_text, photo_path, reference_audio=None):
20
+ # Clone voice if reference audio is provided
21
+ if reference_audio:
22
+ audio_path = clone_voice(resume_text, reference_audio)
23
+ else:
24
+ # Fallback to gTTS
25
+ tts = gTTS(text=resume_text, lang='en')
26
+ audio_path = "output.mp3"
27
+ tts.save(audio_path)
28
+
29
+ # Create lip-sync video (simplified example)
30
+ video_path = "output.mp4"
31
+ os.system(f"ffmpeg -loop 1 -i {photo_path} -i {audio_path} -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest {video_path}")
32
+
33
+ return video_path
34
+
35
+ with gr.Blocks() as demo:
36
+ gr.Markdown("# 🎤 Voice My Resume (with Voice Cloning)")
37
+
38
+ with gr.Tab("Standard Voice"):
39
+ text_input1 = gr.Textbox(label="Paste Resume Text")
40
+ image_input1 = gr.Image(label="Upload Photo", type="filepath")
41
+ generate_btn1 = gr.Button("Generate with Default Voice")
42
+
43
+ with gr.Tab("Clone Your Voice"):
44
+ text_input2 = gr.Textbox(label="Paste Resume Text")
45
+ image_input2 = gr.Image(label="Upload Photo", type="filepath")
46
+ audio_input = gr.Audio(label="Upload 10s Reference Audio", type="filepath")
47
+ generate_btn2 = gr.Button("Generate with Cloned Voice")
48
+
49
+ video_output = gr.Video(label="Result")
50
+
51
+ generate_btn1.click(
52
+ fn=generate_video_resume,
53
+ inputs=[text_input1, image_input1],
54
+ outputs=video_output
55
+ )
56
+
57
+ generate_btn2.click(
58
+ fn=generate_video_resume,
59
+ inputs=[text_input2, image_input2, audio_input],
60
+ outputs=video_output
61
+ )
62
+
63
+ demo.launch()