Skip to content

Commit

Permalink
fix: pitch shift example
Browse files Browse the repository at this point in the history
  • Loading branch information
varshith15 committed Feb 3, 2025
1 parent 1c1959e commit 6e134b7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
3 changes: 2 additions & 1 deletion nodes/audio_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .load_audio_tensor import LoadAudioTensor
from .save_audio_tensor import SaveAudioTensor
from .pitch_shift import PitchShifter

NODE_CLASS_MAPPINGS = {"LoadAudioTensor": LoadAudioTensor, "SaveAudioTensor": SaveAudioTensor}
NODE_CLASS_MAPPINGS = {"LoadAudioTensor": LoadAudioTensor, "SaveAudioTensor": SaveAudioTensor, "PitchShifter": PitchShifter}

__all__ = ["NODE_CLASS_MAPPINGS"]
32 changes: 32 additions & 0 deletions nodes/audio_utils/pitch_shift.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import numpy as np
import librosa

class PitchShifter:
CATEGORY = "audio_utils"
RETURN_TYPES = ("WAVEFORM", "INT")
FUNCTION = "execute"

@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"audio": ("WAVEFORM",),
"sample_rate": ("INT",),
"pitch_shift": ("FLOAT", {
"default": 4.0,
"min": 0.0,
"max": 12.0,
"step": 0.5
}),
}
}

@classmethod
def IS_CHANGED(cls):
return float("nan")

def execute(self, audio, sample_rate, pitch_shift):
audio_float = audio.astype(np.float32) / 32768.0
shifted_audio = librosa.effects.pitch_shift(audio_float, sample_rate, n_steps=pitch_shift)
shifted_int16 = np.clip(shifted_audio * 32768.0, -32768, 32767).astype(np.int16)
return shifted_int16, sample_rate
24 changes: 19 additions & 5 deletions workflows/audio-tensor-utils-example-workflow.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"1": {
"inputs": {
"buffer_size": 200.0,
"sample_rate": 48000
"buffer_size": 500.0
},
"class_type": "LoadAudioTensor",
"_meta": {
Expand All @@ -15,12 +14,27 @@
"1",
0
],
"frame_size": 20.0,
"sample_rate": 48000
"sample_rate": [
"1",
1
],
"pitch_shift": 4.0
},
"class_type": "PitchShifter",
"_meta": {
"title": "Pitch Shift"
}
},
"3": {
"inputs": {
"audio": [
"2",
0
]
},
"class_type": "SaveAudioTensor",
"_meta": {
"title": "Save Audio Tensor"
}
}
}
}

0 comments on commit 6e134b7

Please sign in to comment.