combine.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import sox
  2. import os
  3. import glob
  4. cwd = os.getcwd()
  5. def sortKeyFunc(s):
  6. return int(os.path.basename(s)[:-4])
  7. # remix dual mono
  8. # input_filenames = sorted(glob.glob(cwd + '/vocal/*.wav'), key=sortKeyFunc)
  9. # output_directory = cwd + '/remix_vocal'
  10. # def create_output_filename_padded(input_filename, output_dir):
  11. # return os.path.join(output_dir, 'remix', os.path.split(input_filename)[1])
  12. # for input_file in input_filenames:
  13. # t = sox.Transformer()
  14. # remix_dictionary = {1: [1], 2: [1]}
  15. # remix_dictionary = {1: [2], 2: [2]}
  16. # t.remix(remix_dictionary)
  17. # out_name = create_output_filename_padded(input_file, output_directory)
  18. # os.makedirs(os.path.split(out_name)[0], exist_ok=True)
  19. # t.build(input_file, out_name)
  20. # norm - fade - pad
  21. # input_filenames = sorted(glob.glob(cwd + '/remix_field/remix/*.wav'), key=sortKeyFunc)
  22. # output_directory = cwd + '/padded_field'
  23. # def create_output_filename_padded(input_filename, output_dir):
  24. # return os.path.join(output_dir, 'padded', os.path.split(input_filename)[1])
  25. # for input_file in input_filenames:
  26. # t = sox.Transformer()
  27. # t.norm(-3)
  28. # t.fade(fade_in_len=0.2, fade_out_len=0.2)
  29. # t.pad(1, 0)
  30. # out_name = create_output_filename_padded(input_file, output_directory)
  31. # os.makedirs(os.path.split(out_name)[0], exist_ok=True)
  32. # t.build(input_file, out_name)
  33. # combine code
  34. cbn = sox.Combiner()
  35. audio_one = sorted(glob.glob(cwd + '/padded_field/padded/*.wav'), key=sortKeyFunc)
  36. audio_two = sorted(glob.glob(cwd + '/padded_vocal/padded/*.wav'), key=sortKeyFunc)
  37. paired_audio = [list(x) for x in zip(audio_one, audio_two)]
  38. # paired_audio = [list(x) for x in zip(audio_two, audio_one)]
  39. def combine():
  40. for n in paired_audio:
  41. out_name = os.path.split(n[0])[1].replace('.wav', '') + '_and_' + 'vocal' + os.path.split(n[1])[1]
  42. cbn.build(n, cwd + '/audio_outputs/' + out_name, 'concatenate')
  43. for afunc in (remix, pad_three_seconds, pad_one_second, combine):
  44. afunc()