Rejekts commited on
Commit
790d00b
1 Parent(s): f1108f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -4
app.py CHANGED
@@ -9,10 +9,32 @@ os.environ['weight_root']="assets/weights"
9
  from infer.modules.vc.modules import VC
10
  from configs.config import Config
11
  import torch
 
 
12
  os.makedirs(os.path.join(".", "audios"), exist_ok=True)
13
  config = Config()
14
  vc = VC(config)
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def warn(text):
17
  try: gr.Warning(text)
18
  except: pass
@@ -289,9 +311,14 @@ with gr.Blocks() as app:
289
  audio_refresher.click(fn=refresh,inputs=[],outputs=[audio_picker,model_picker,index_picker])
290
  convert_button = gr.Button("Convert")
291
  with gr.Row():
292
- audio_player = gr.Audio()
293
- inputs = [audio_picker,model_picker,index_picker,index_rate,pitch,method]
294
- audio_picker.change(fn=update_audio_player, inputs=[audio_picker],outputs=[audio_player])
295
- convert_button.click(convert, inputs=inputs,outputs=[audio_picker,audio_player])
 
 
 
 
 
296
 
297
  app.queue(max_size=20).launch(debug=True,allowed_paths=["kofi_button.png"])
 
9
  from infer.modules.vc.modules import VC
10
  from configs.config import Config
11
  import torch
12
+ from pydub import AudioSegment
13
+ import numpy as np
14
  os.makedirs(os.path.join(".", "audios"), exist_ok=True)
15
  config = Config()
16
  vc = VC(config)
17
 
18
+ def stereo(audio_path, delay_ms=0.6):
19
+ sample_rate, audio_array = audio_path
20
+ if len(audio_array.shape) == 1:
21
+ audio_bytes = audio_array.tobytes()
22
+ mono_audio = AudioSegment(
23
+ data=audio_bytes,
24
+ sample_width=audio_array.dtype.itemsize, # 2 bytes for int16
25
+ frame_rate=sample_rate, # Use the sample rate from your tuple
26
+ channels=1 # Adjust if your audio has more channels
27
+ )
28
+ samples = np.array(mono_audio.get_array_of_samples())
29
+ delay_samples = int(mono_audio.frame_rate * (delay_ms / 1000.0))
30
+ left_channel = np.zeros_like(samples)
31
+ right_channel = samples
32
+ left_channel[delay_samples:] = samples[:-delay_samples] #Offset to the left
33
+ stereo_samples = np.column_stack((left_channel, right_channel))
34
+ return (sample_rate, stereo_samples.astype(np.int16))
35
+ else:
36
+ return audio_path
37
+
38
  def warn(text):
39
  try: gr.Warning(text)
40
  except: pass
 
311
  audio_refresher.click(fn=refresh,inputs=[],outputs=[audio_picker,model_picker,index_picker])
312
  convert_button = gr.Button("Convert")
313
  with gr.Row():
314
+ with gr.Tabs():
315
+ with gr.TabItem("Original"):
316
+ audio_player = gr.Audio()
317
+ inputs = [audio_picker,model_picker,index_picker,index_rate,pitch,method]
318
+ audio_picker.change(fn=update_audio_player, inputs=[audio_picker],outputs=[audio_player])
319
+ convert_button.click(convert, inputs=inputs,outputs=[audio_picker,audio_player])
320
+ with gr.TabItem("Stereo"):
321
+ stereo_player = gr.Audio()
322
+ audio_player.change(fn=stereo, inputs=[audio_player],outputs=[stereo_player])
323
 
324
  app.queue(max_size=20).launch(debug=True,allowed_paths=["kofi_button.png"])