Skip to content

Commit 6e134b7

Browse files
committed
fix: pitch shift example
1 parent 1c1959e commit 6e134b7

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

nodes/audio_utils/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .load_audio_tensor import LoadAudioTensor
22
from .save_audio_tensor import SaveAudioTensor
3+
from .pitch_shift import PitchShifter
34

4-
NODE_CLASS_MAPPINGS = {"LoadAudioTensor": LoadAudioTensor, "SaveAudioTensor": SaveAudioTensor}
5+
NODE_CLASS_MAPPINGS = {"LoadAudioTensor": LoadAudioTensor, "SaveAudioTensor": SaveAudioTensor, "PitchShifter": PitchShifter}
56

67
__all__ = ["NODE_CLASS_MAPPINGS"]

nodes/audio_utils/pitch_shift.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import numpy as np
2+
import librosa
3+
4+
class PitchShifter:
5+
CATEGORY = "audio_utils"
6+
RETURN_TYPES = ("WAVEFORM", "INT")
7+
FUNCTION = "execute"
8+
9+
@classmethod
10+
def INPUT_TYPES(cls):
11+
return {
12+
"required": {
13+
"audio": ("WAVEFORM",),
14+
"sample_rate": ("INT",),
15+
"pitch_shift": ("FLOAT", {
16+
"default": 4.0,
17+
"min": 0.0,
18+
"max": 12.0,
19+
"step": 0.5
20+
}),
21+
}
22+
}
23+
24+
@classmethod
25+
def IS_CHANGED(cls):
26+
return float("nan")
27+
28+
def execute(self, audio, sample_rate, pitch_shift):
29+
audio_float = audio.astype(np.float32) / 32768.0
30+
shifted_audio = librosa.effects.pitch_shift(audio_float, sample_rate, n_steps=pitch_shift)
31+
shifted_int16 = np.clip(shifted_audio * 32768.0, -32768, 32767).astype(np.int16)
32+
return shifted_int16, sample_rate
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"1": {
33
"inputs": {
4-
"buffer_size": 200.0,
5-
"sample_rate": 48000
4+
"buffer_size": 500.0
65
},
76
"class_type": "LoadAudioTensor",
87
"_meta": {
@@ -15,12 +14,27 @@
1514
"1",
1615
0
1716
],
18-
"frame_size": 20.0,
19-
"sample_rate": 48000
17+
"sample_rate": [
18+
"1",
19+
1
20+
],
21+
"pitch_shift": 4.0
22+
},
23+
"class_type": "PitchShifter",
24+
"_meta": {
25+
"title": "Pitch Shift"
26+
}
27+
},
28+
"3": {
29+
"inputs": {
30+
"audio": [
31+
"2",
32+
0
33+
]
2034
},
2135
"class_type": "SaveAudioTensor",
2236
"_meta": {
2337
"title": "Save Audio Tensor"
2438
}
2539
}
26-
}
40+
}

0 commit comments

Comments
 (0)