Vaishnavi0404 commited on
Commit
ee3dec5
·
verified ·
1 Parent(s): 5c983be

Update diff_singer_infer.py

Browse files
Files changed (1) hide show
  1. diff_singer_infer.py +15 -19
diff_singer_infer.py CHANGED
@@ -1,29 +1,25 @@
1
- import numpy as np
2
  import torchaudio
 
3
  import pyworld as pw
4
- import soundfile as sf
5
- from scipy.interpolate import interp1d
6
 
7
  def extract_pitch(audio, sr):
8
- # Convert audio to double precision for pyworld
9
- audio = audio.astype(np.float64)
10
-
11
- _f0, t = pw.dio(audio, sr)
12
- f0 = pw.stonemask(audio, _f0, t, sr)
13
  return f0
14
 
15
- def run_diffsinger_inference(input_audio_path):
16
- waveform, sr = torchaudio.load(input_audio_path)
17
- audio = waveform[0].numpy() # Mono
18
- f0 = extract_pitch(audio, sr)
19
 
20
- # Simple manipulation to simulate expressiveness
21
- f0_smooth = interp1d(np.arange(len(f0)), f0, kind='cubic', fill_value="extrapolate")(np.linspace(0, len(f0)-1, len(f0)))
22
- f0_smooth *= 1.15 # Slight pitch boost
23
 
24
- # Pitch-shifted output
25
- output_audio = pw.synthesize(f0_smooth, pw.cheaptrick(audio.astype(np.float64), f0, np.linspace(0, len(audio)/sr, len(f0)), sr), pw.d4c(audio.astype(np.float64), f0, np.linspace(0, len(audio)/sr, len(f0)), sr), sr)
26
 
27
- output_path = "output_singing.wav"
28
- sf.write(output_path, output_audio, sr)
 
29
  return output_path
 
 
1
  import torchaudio
2
+ import numpy as np
3
  import pyworld as pw
4
+ import scipy.io.wavfile as wavfile
 
5
 
6
  def extract_pitch(audio, sr):
7
+ _f0, t = pw.dio(audio.astype(np.float64), sr)
8
+ f0 = pw.stonemask(audio.astype(np.float64), _f0, t, sr)
 
 
 
9
  return f0
10
 
11
+ def run_diffsinger_inference(input_path):
12
+ # Load audio
13
+ waveform, sr = torchaudio.load(input_path)
14
+ audio = waveform[0].numpy()
15
 
16
+ # Pitch extraction
17
+ f0 = extract_pitch(audio, sr)
 
18
 
19
+ # Simulate pitch & vibrato mod (placeholder until DiffSinger model added)
20
+ new_audio = audio * 0.8 # just reduce volume for test
21
 
22
+ # Save as WAV
23
+ output_path = "/tmp/output_singing.wav"
24
+ wavfile.write(output_path, sr, (new_audio * 32767).astype(np.int16))
25
  return output_path