Awell00 commited on
Commit
3bc754b
·
verified ·
1 Parent(s): 7a46bef

fix: resolve issue causing corrupted MP3 files during export

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -189,13 +189,13 @@ def move_stems_to_parent(input_dir):
189
  new_instrumental_path = os.path.join(parent_dir, "instrumental.wav")
190
  shutil.move(instrumental_path, new_instrumental_path)
191
 
192
- def combine_stems_for_all(input_dir, output_format):
193
  """
194
- Combine all stems for each song in the input directory.
195
 
196
  Args:
197
  input_dir (str): Input directory containing song folders
198
- output_format (str): Output audio format (e.g., 'm4a')
199
 
200
  Returns:
201
  str: Path to the combined audio file
@@ -226,19 +226,16 @@ def combine_stems_for_all(input_dir, output_format):
226
  # Trim silence at the end
227
  trimmed_combined = trim_silence_at_end(combined)
228
 
229
- # Use .m4a extension for AAC audio
230
- output_file = os.path.join(subdir, song_name)
231
 
232
  try:
233
- # Export combined audio
234
- trimmed_combined.export(output_file, format="ipod", codec="aac")
235
- print(f"Exported combined stems to {output_file}")
236
- except CouldntEncodeError as e:
237
- print(f"Encoding failed: {e}")
238
- # Fallback to MP3 if M4A fails
239
- output_file = os.path.join(subdir, f"{song_name}.mp3")
240
  trimmed_combined.export(output_file, format="mp3", codec="libmp3lame", bitrate="320k")
241
  print(f"Exported combined stems to MP3 format: {output_file}")
 
 
 
242
 
243
  return output_file
244
 
 
189
  new_instrumental_path = os.path.join(parent_dir, "instrumental.wav")
190
  shutil.move(instrumental_path, new_instrumental_path)
191
 
192
+ def combine_stems_for_all(input_dir, output_format="mp3"):
193
  """
194
+ Combine all stems for each song in the input directory and export as MP3.
195
 
196
  Args:
197
  input_dir (str): Input directory containing song folders
198
+ output_format (str): Output audio format (default is 'mp3')
199
 
200
  Returns:
201
  str: Path to the combined audio file
 
226
  # Trim silence at the end
227
  trimmed_combined = trim_silence_at_end(combined)
228
 
229
+ # Set MP3 as the output format
230
+ output_file = os.path.join(subdir, f"{song_name}.{output_format}")
231
 
232
  try:
233
+ # Export combined audio to MP3
 
 
 
 
 
 
234
  trimmed_combined.export(output_file, format="mp3", codec="libmp3lame", bitrate="320k")
235
  print(f"Exported combined stems to MP3 format: {output_file}")
236
+ except CouldntEncodeError as e:
237
+ print(f"MP3 Encoding failed: {e}")
238
+ return None
239
 
240
  return output_file
241