-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
62 lines (49 loc) · 1.8 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
OpenDub: Audio dubbing application.
This script performs:
1. Emotion detection from input audio
2. Subtitle translation
3. Voice cloning for translated text
Usage: Run directly with default inputs or modify file paths in main().
Dependencies: src.model.emotion_recognition, src.model.translation, src.model.voice_cloning, os
"""
import os
from src.model.emotion_recognition import detect_emotion
from src.model.translation import translate_subtitles
from src.model.voice_cloning import voice_clone
def main():
"""
Run the OpenDub application.
Steps:
1. Set up file paths
2. Detect emotion
3. Translate subtitles
4. Generate dubbed audio
Raises:
FileNotFoundError: If input files are missing.
RuntimeError: If processing fails.
"""
try:
audio_file = 'src/audio/input_audio.wav'
subtitle_file = 'src/subtitles/input_subtitles.srt'
output_file = 'src/output/output_audio.wav'
os.makedirs(os.path.dirname(output_file), exist_ok=True)
print("Detecting emotion...")
emotion = detect_emotion(audio_file)
print(f"Detected Emotion: {emotion}")
print("Translating subtitles...")
translated_subs = translate_subtitles(subtitle_file, target_lang='en')
for sub in translated_subs:
print(sub.text)
print("Generating dubbed audio...")
full_text = " ".join([sub.text for sub in translated_subs])
voice_clone(audio_file, full_text, output_file)
print(f"Dubbed audio saved to {output_file}")
except FileNotFoundError as e:
print(f"Error: Input file not found. {e}")
except RuntimeError as e:
print(f"Error: Processing failed. {e}")
except Exception as e:
print(f"Unexpected error: {e}")
if __name__ == '__main__':
main()