jeonchangbin49 commited on
Commit
28dfe16
·
1 Parent(s): 9e538da

now supports other sample rates

Browse files
Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  import json
3
  import argparse
 
4
 
5
  import numpy as np
6
  import matplotlib.pyplot as plt
@@ -147,13 +148,19 @@ def main(input, mix_coefficient):
147
  meter = pyln.Meter(44100)
148
 
149
  sr, track_audio = input
 
150
  track_audio = track_audio.T
151
  track_name = "gradio_demo"
152
 
 
 
 
 
 
 
 
153
  orig_audio = track_audio.copy()
154
 
155
- if sr != 44100:
156
- raise ValueError("Sample rate should be 44100")
157
  augmented_gain = None
158
 
159
  if args.loudnorm_input_lufs: # If you want to use loud-normalized input
@@ -169,6 +176,8 @@ def main(input, mix_coefficient):
169
  args, our_model, device, track_audio, track_name, meter, augmented_gain
170
  )
171
 
 
 
172
  orig_audio = int16_to_float32(orig_audio)
173
  track_lufs = meter.integrated_loudness(orig_audio.T)
174
  augmented_gain = args.save_output_loudnorm - track_lufs
@@ -206,11 +215,16 @@ with gr.Blocks() as demo:
206
  </h1>
207
  </div>
208
  <p style="margin-bottom: 10px; font-size: 94%">
209
- A demo for "Music De-limiter via Sample-wise Gain Inversion" to appear in WASPAA 2023.
210
- You can first upload a music (.wav or .mp3, 44.1kHz) file and then press "De-limit" button to apply the De-limiter. Since we use a CPU instead of a GPU, it may require a few minute.
211
- Then, you can apply a Parallel Mix technique, which is a simple linear mixing technique of "loudness normalized input" and the "de-limiter output".
212
- You can modify the mixing coefficient by yourself.
213
- If the coefficient is 0.3 then the output will be "loudness_normalized_input * 0.3 + de-limiter_output * 0.7"
 
 
 
 
 
214
  </div>
215
  """
216
  )
 
1
  import os
2
  import json
3
  import argparse
4
+ import copy
5
 
6
  import numpy as np
7
  import matplotlib.pyplot as plt
 
148
  meter = pyln.Meter(44100)
149
 
150
  sr, track_audio = input
151
+ orig_sr = copy.deepcopy(sr)
152
  track_audio = track_audio.T
153
  track_name = "gradio_demo"
154
 
155
+ if sr != 44100:
156
+ track_audio = int16_to_float32(track_audio)
157
+ track_audio = librosa.resample(
158
+ track_audio, orig_sr=sr, target_sr=44100, res_type="soxr_vhq"
159
+ )
160
+ sr = 44100
161
+
162
  orig_audio = track_audio.copy()
163
 
 
 
164
  augmented_gain = None
165
 
166
  if args.loudnorm_input_lufs: # If you want to use loud-normalized input
 
176
  args, our_model, device, track_audio, track_name, meter, augmented_gain
177
  )
178
 
179
+ if orig_sr == 44100:
180
+ orig_audio = int16_to_float32(orig_audio)
181
  orig_audio = int16_to_float32(orig_audio)
182
  track_lufs = meter.integrated_loudness(orig_audio.T)
183
  augmented_gain = args.save_output_loudnorm - track_lufs
 
215
  </h1>
216
  </div>
217
  <p style="margin-bottom: 10px; font-size: 94%">
218
+ A demo for "Music De-limiter via Sample-wise Gain Inversion" to appear in WASPAA 2023.<br>
219
+ Upload a stereo music (tested with .wav, .mp3, .m4a) file and then press "De-limit" button to apply the De-limiter.<br>
220
+ The processing is based on 44.1kHz sample rate. Other sample rate will be automatically resampled to 44.1kHz.<br>
221
+ Since we use a CPU instead of a GPU, it may require a few seconds to minutes.<br>
222
+ Then, you can apply a Parallel Mix technique, which is a simple linear mixing technique of "loudness normalized input" and the "de-limiter output", similar to Parallel Compression.<br>
223
+ If the coefficient is 0.3 then the output will be the "loudness_normalized_input * 0.3 + de-limiter_output * 0.7"<br>
224
+ Check our Paper <a href="https://arxiv.org/abs/2308.01187">[arXiv]</a>
225
+ Codes <a href="<a href="https://github.com/jeonchangbin49/De-limiter">[GitHub]</a>
226
+ Audio samples <a href="<a href="https://catnip-leaf-c6a.notion.site/Music-De-limiter-7072c0e725fd42249ff78cbbaedc95d7?pvs=4">[Notion]</a> <br>
227
+ Please let me know any issues or comments on [email protected] or the "Community" page (the upper right section of this page).
228
  </div>
229
  """
230
  )