R-Kentaren commited on
Commit
b2b82a4
·
verified ·
1 Parent(s): 9e6f98e

Update pitch/inference.py

Browse files
Files changed (1) hide show
  1. pitch/inference.py +18 -1
pitch/inference.py CHANGED
@@ -4,7 +4,24 @@ import librosa
4
  import argparse
5
  import numpy as np
6
  import parselmouth
7
- # pip install praat-parselmouth
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  def compute_f0_mouth(path):
10
  x, sr = librosa.load(path, sr=16000)
 
4
  import argparse
5
  import numpy as np
6
  import parselmouth
7
+ from pitch.rmvpe import RMVPE
8
+ import torch
9
+ import numpy as np
10
+
11
+ def compute_f0_rmvpe(path, model_path='rmvpe.pt'):
12
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
13
+ model = RMVPE(model_path, is_half=False, device=device)
14
+ x, sr = librosa.load(path, sr=16000)
15
+ assert sr == 16000
16
+ f0 = model.infer_from_audio(x)
17
+ # Adjust to 10 ms resolution by repeating (assuming 20 ms output)
18
+ f0 = np.repeat(f0, 2)
19
+ # Pad f0 to match other functions
20
+ lpad = 6
21
+ rpad = 6
22
+ f0 = np.pad(f0, [lpad, rpad], mode='constant')
23
+ return f0
24
+
25
 
26
  def compute_f0_mouth(path):
27
  x, sr = librosa.load(path, sr=16000)