Skip to content

Commit 927bba6

Browse files
authored
Merge pull request #1077 from icecoins/master
implement of the fcpe in RVC
2 parents 4123825 + 8f230e5 commit 927bba6

File tree

7 files changed

+52
-2
lines changed

7 files changed

+52
-2
lines changed

client/demo/dist/assets/gui_settings/GUI.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{
2222
"name": "configArea",
2323
"options": {
24-
"detectors": ["dio", "harvest", "crepe", "crepe_full", "crepe_tiny", "rmvpe", "rmvpe_onnx"],
24+
"detectors": ["dio", "harvest", "crepe", "crepe_full", "crepe_tiny", "rmvpe", "rmvpe_onnx", "fcpe" ],
2525
"inputChunkNums": [1, 2, 4, 6, 8, 16, 24, 32, 40, 48, 64, 80, 96, 112, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024, 2048, 4096, 8192, 16384]
2626
}
2727
}

client/demo/public/assets/gui_settings/GUI.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{
2222
"name": "configArea",
2323
"options": {
24-
"detectors": ["dio", "harvest", "crepe", "crepe_full", "crepe_tiny", "rmvpe", "rmvpe_onnx"],
24+
"detectors": ["dio", "harvest", "crepe", "crepe_full", "crepe_tiny", "rmvpe", "rmvpe_onnx", "fcpe"],
2525
"inputChunkNums": [1, 2, 4, 6, 8, 16, 24, 32, 40, 48, 64, 80, 96, 112, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024, 2048, 4096, 8192, 16384]
2626
}
2727
}

client/lib/src/const.ts

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const F0Detector = {
5656
crepe_tiny: "crepe_tiny",
5757
rmvpe: "rmvpe",
5858
rmvpe_onnx: "rmvpe_onnx",
59+
fcpe: "fcpe",
5960
} as const;
6061
export type F0Detector = (typeof F0Detector)[keyof typeof F0Detector];
6162

server/const.py

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class EnumInferenceTypes(Enum):
8282
"crepe_tiny",
8383
"rmvpe",
8484
"rmvpe_onnx",
85+
"fcpe",
8586
]
8687

8788
ServerAudioDeviceType: TypeAlias = Literal["audioinput", "audiooutput"]

server/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ websockets==11.0.2
2727
sounddevice==0.4.6
2828
dataclasses_json==0.5.7
2929
onnxsim==0.4.28
30+
torchfcpe
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import numpy as np
2+
from const import PitchExtractorType
3+
from voice_changer.RVC.deviceManager.DeviceManager import DeviceManager
4+
from voice_changer.RVC.pitchExtractor.PitchExtractor import PitchExtractor
5+
import torchfcpe
6+
7+
class FcpePitchExtractor(PitchExtractor):
8+
9+
def __init__(self, gpu: int):
10+
super().__init__()
11+
self.pitchExtractorType: PitchExtractorType = "fcpe"
12+
self.device = DeviceManager.get_instance().getDevice(gpu)
13+
self.fcpe = torchfcpe.spawn_bundled_infer_model(self.device)
14+
15+
# I merge the code of Voice-Changer-CrepePitchExtractor and RVC-fcpe-infer, sry I don't know how to optimize the function.
16+
def extract(self, audio, pitchf, f0_up_key, sr, window, silence_front=0):
17+
start_frame = int(silence_front * sr / window)
18+
real_silence_front = start_frame * window / sr
19+
20+
silence_front_offset = int(np.round(real_silence_front * sr))
21+
audio = audio[silence_front_offset:]
22+
23+
f0_min = 50
24+
f0_max = 1100
25+
f0_mel_min = 1127 * np.log(1 + f0_min / 700)
26+
f0_mel_max = 1127 * np.log(1 + f0_max / 700)
27+
28+
f0 = self.fcpe.infer(
29+
audio.to(self.device).unsqueeze(0).float(),
30+
sr=16000,
31+
decoder_mode="local_argmax",
32+
threshold=0.006,
33+
)
34+
f0 = f0.squeeze()
35+
36+
f0 *= pow(2, f0_up_key / 12)
37+
pitchf[-f0.shape[0]:] = f0.detach().cpu().numpy()[:pitchf.shape[0]]
38+
f0bak = pitchf.copy()
39+
f0_mel = 1127.0 * np.log(1.0 + f0bak / 700.0)
40+
f0_mel = np.clip(
41+
(f0_mel - f0_mel_min) * 254.0 / (f0_mel_max - f0_mel_min) + 1.0, 1.0, 255.0
42+
)
43+
pitch_coarse = f0_mel.astype(int)
44+
return pitch_coarse, pitchf

server/voice_changer/RVC/pitchExtractor/PitchExtractorManager.py

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def loadPitchExtractor(
4343
return RMVPEPitchExtractor(cls.params.rmvpe, gpu)
4444
elif pitchExtractorType == "rmvpe_onnx":
4545
return RMVPEOnnxPitchExtractor(cls.params.rmvpe_onnx, gpu)
46+
elif pitchExtractorType == "fcpe":
47+
# add the FcpePitchExtractor
48+
return FcpePitchExtractor(gpu)
4649
else:
4750
# return hubert as default
4851
print("[Voice Changer] PitchExctractor not found", pitchExtractorType)

0 commit comments

Comments
 (0)