Maximofn commited on
Commit
4a317df
1 Parent(s): b1e9205

Fix some bugs of separe.py

Browse files
Files changed (1) hide show
  1. separe.py +9 -4
separe.py CHANGED
@@ -54,7 +54,7 @@ def set_mono(input_audio_file_path, output_audio_file_path):
54
  def main(args):
55
  # Get input and output files
56
  input = args.input
57
- output = args.output
58
 
59
  # Get input and output names
60
  input_name = input.split(".")[0]
@@ -74,14 +74,18 @@ def main(args):
74
  sr = get_sample_rate(input)
75
  if sr != SAMPLE_RATE:
76
  change_sample_rate(input, input_8k, SAMPLE_RATE)
 
77
  else:
78
  input_8k = input
 
79
 
80
  # Check if input is stereo, if yes, set it to mono
81
  if audio_is_stereo(input_8k):
82
  set_mono(input_8k, input_8k_mono)
 
83
  else:
84
  input_8k_mono = input_8k
 
85
 
86
  # Separate audio voices
87
  device = 'cuda' if torch.cuda.is_available() else 'cpu'
@@ -94,12 +98,13 @@ def main(args):
94
  sf.write(save_file, np.frombuffer(signal, dtype=np.int16), SAMPLE_RATE)
95
 
96
  # Remove temporary files
97
- os.remove(input_8k)
98
- os.remove(input_8k_mono)
 
 
99
 
100
  if __name__ == '__main__':
101
  argparser = argparse.ArgumentParser(description='Separate speech from a stereo audio file')
102
  argparser.add_argument('input', type=str, help='Input audio file')
103
- argparser.add_argument('output', type=str, help='Output directory')
104
  args = argparser.parse_args()
105
  main(args)
 
54
  def main(args):
55
  # Get input and output files
56
  input = args.input
57
+ output = args.input
58
 
59
  # Get input and output names
60
  input_name = input.split(".")[0]
 
74
  sr = get_sample_rate(input)
75
  if sr != SAMPLE_RATE:
76
  change_sample_rate(input, input_8k, SAMPLE_RATE)
77
+ remove_8k = True
78
  else:
79
  input_8k = input
80
+ remove_8k = False
81
 
82
  # Check if input is stereo, if yes, set it to mono
83
  if audio_is_stereo(input_8k):
84
  set_mono(input_8k, input_8k_mono)
85
+ remove_mono = True
86
  else:
87
  input_8k_mono = input_8k
88
+ remove_mono = False
89
 
90
  # Separate audio voices
91
  device = 'cuda' if torch.cuda.is_available() else 'cpu'
 
98
  sf.write(save_file, np.frombuffer(signal, dtype=np.int16), SAMPLE_RATE)
99
 
100
  # Remove temporary files
101
+ if remove_8k:
102
+ os.remove(input_8k)
103
+ if remove_mono:
104
+ os.remove(input_8k_mono)
105
 
106
  if __name__ == '__main__':
107
  argparser = argparse.ArgumentParser(description='Separate speech from a stereo audio file')
108
  argparser.add_argument('input', type=str, help='Input audio file')
 
109
  args = argparser.parse_args()
110
  main(args)