@@ -150,12 +150,12 @@ def main():
150
150
base_directory = os .getcwd ()
151
151
output_directory = os .path .join (base_directory , "output" )
152
152
audio_directory = os .path .join (base_directory , "audio" )
153
- video_file_name = input_file . split (os .sep )[ - 1 ]. split ( "." )[0 ]
154
- audio_file_name = os .path .join (audio_directory , video_file_name + ".wav" )
153
+ video_prefix = os . path . splitext (os .path . basename ( input_file ) )[0 ]
154
+ audio_file_name = os .path .join (audio_directory , video_prefix + ".wav" )
155
155
156
156
output_file_handle_dict = {}
157
157
for format in args .format :
158
- output_filename = os .path .join (output_directory , video_file_name + "." + format )
158
+ output_filename = os .path .join (output_directory , video_prefix + "." + format )
159
159
print ("Creating file: " + output_filename )
160
160
output_file_handle_dict [format ] = open (output_filename , "w" )
161
161
# For VTT format, write header
@@ -165,14 +165,15 @@ def main():
165
165
166
166
# Clean audio/ directory
167
167
for filename in os .listdir (audio_directory ):
168
- file_path = os .path .join (audio_directory , filename )
169
- try :
170
- if os .path .isfile (file_path ) or os .path .islink (file_path ):
171
- os .unlink (file_path )
172
- elif os .path .isdir (file_path ):
173
- shutil .rmtree (file_path )
174
- except Exception as e :
175
- print ('Failed to delete %s. Reason: %s' % (file_path , e ))
168
+ if filename .lower ().endswith (".wav" ) and filename .startswith (video_prefix ):
169
+ file_path = os .path .join (audio_directory , filename )
170
+ try :
171
+ if os .path .isfile (file_path ) or os .path .islink (file_path ):
172
+ os .unlink (file_path )
173
+ elif os .path .isdir (file_path ):
174
+ shutil .rmtree (file_path )
175
+ except Exception as e :
176
+ print ('Failed to delete %s. Reason: %s' % (file_path , e ))
176
177
177
178
# Extract audio from input video file
178
179
extract_audio (input_file , audio_file_name )
@@ -182,11 +183,10 @@ def main():
182
183
183
184
print ("\n Running inference:" )
184
185
185
- for file in tqdm (sort_alphanumeric (os .listdir (audio_directory ))):
186
- audio_segment_path = os .path .join (audio_directory , file )
187
-
188
- # Dont run inference on the original audio file
189
- if audio_segment_path .split (os .sep )[- 1 ] != audio_file_name .split (os .sep )[- 1 ]:
186
+ for filename in tqdm (sort_alphanumeric (os .listdir (audio_directory ))):
187
+ # Only run inference on relevant files, and don't run inference on the original audio file
188
+ if filename .startswith (video_prefix ) and (filename != os .path .basename (audio_file_name )):
189
+ audio_segment_path = os .path .join (audio_directory , filename )
190
190
ds_process_audio (ds , audio_segment_path , output_file_handle_dict , split_duration = args .split_duration )
191
191
192
192
print ("\n " )
0 commit comments