3
3
from tools .audio_splitter_ffmpeg import *
4
4
from tools .video_downloader import *
5
5
from tools .video_editing import *
6
+ import sys
6
7
7
8
if __name__ == '__main__' :
8
9
# Prepare folders
12
13
os .makedirs ('final_output' , exist_ok = True )
13
14
os .makedirs ('logs' , exist_ok = True )
14
15
16
+ # Redirect all print outputs to a log file
17
+ # log_output_file = open('logs/log.txt', 'w')
18
+ # sys.stdout = log_output_file
19
+
15
20
# Set the multiprocessing start method to 'spawn'
16
21
multiprocessing .set_start_method ('spawn' )
17
22
18
23
# Download video
19
- # url = input("Enter YouTube URL: ")
20
- # video = video_download(url)
21
- video = "downloads/xSh7PuWAxXU.mp4"
24
+ url = input ("Enter YouTube URL: " )
25
+ video = video_download (url )
26
+ # video = "downloads/xSh7PuWAxXU.mp4"
22
27
23
28
# # Extract audio
24
- # audio = audio_extractor(video)
29
+ audio = audio_extractor (video )
25
30
26
31
## Load audio
27
- audio = 'original_audios/xSh7PuWAxXU.wav'
32
+ # audio = 'original_audios/xSh7PuWAxXU.wav'
28
33
original_audio_name = os .path .splitext (os .path .basename (audio ))[0 ]
29
34
30
35
## Transcribe audio
36
41
print ("Audio split" )
37
42
38
43
## Translate each segment
39
- # new_segments = []
40
- # i = 0
41
- # total_segments = len(segments)
42
- # for segment in segments:
43
- # if len(segment['text']) > 0:
44
- # translated_text = translate_deepl(segment['text'], 'es', detected_language)
45
- # else:
46
- # translated_text = ''
47
- # new_segments.append({'id': segment['id'],
48
- # 'seek': segment['seek'],
49
- # 'start': segment['start'],
50
- # 'end': segment['end'],
51
- # 'text': translated_text
52
- # })
53
- # percentage = (i+1)/total_segments*100
54
- # # Print the progress
55
- # print(f'Translation progress: {percentage:.2f}%')
56
- # i += 1
57
- # print(f"Audio translated")
44
+ new_segments = []
45
+ i = 0
46
+ total_segments = len (segments )
47
+ for segment in segments :
48
+ if len (segment ['text' ]) > 0 :
49
+ translated_text = translate_deepl (segment ['text' ], 'es' , detected_language )
50
+ else :
51
+ translated_text = ''
52
+ new_segments .append ({'id' : segment ['id' ],
53
+ 'seek' : segment ['seek' ],
54
+ 'start' : segment ['start' ],
55
+ 'end' : segment ['end' ],
56
+ 'text' : translated_text
57
+ })
58
+ percentage = (i + 1 )/ total_segments * 100
59
+ # Print the progress
60
+ print (f'Translation progress: { percentage :.2f} %' )
61
+ i += 1
62
+ print (f"Audio translated" )
58
63
59
64
## save new_segments as a pickle for later loading
60
- # import pickle
65
+ import pickle
61
66
62
- # with open('new_segments.pkl', 'wb') as f:
63
- # pickle.dump(new_segments, f)
64
- # print("New segments saved")
67
+ with open ('new_segments.pkl' , 'wb' ) as f :
68
+ pickle .dump (new_segments , f )
69
+ print ("New segments saved" )
65
70
66
71
## Load new_segments from pickle
67
72
import pickle
103
108
)
104
109
105
110
# Delete all content in output_audio folder
106
- # for filename in os.listdir('output_audio'):
107
- # file_path = os.path.join('output_audio', filename)
108
- # if os.path.isfile(file_path):
109
- # os.remove(file_path)
111
+ for filename in os .listdir ('output_audio' ):
112
+ file_path = os .path .join ('output_audio' , filename )
113
+ if os .path .isfile (file_path ):
114
+ os .remove (file_path )
110
115
111
116
112
117
# Mix old video file and new audio file
113
118
# video_path = f'downloads/{original_audio_name}.mp4'
114
119
# audio_path = f'final_output/{original_audio_name}-{target_lang_code}.wav'
115
- # replace_audio_in_video(video, audio_path, f'final_output/{original_audio_name}-{target_lang_code}.mp4')
120
+ # replace_audio_in_video(video, audio_path, f'final_output/{original_audio_name}-{target_lang_code}.mp4')
121
+
122
+ # Close log output file
123
+ # sys.stdout = sys.__stdout__
124
+ # log_output_file.close()
0 commit comments