suyash-sarvam commited on
Commit
42e7707
·
verified ·
1 Parent(s): e793c0c

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +3 -9
  2. app.py +44 -0
  3. requirements.txt +4 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Gradio Pitch
3
- emoji: 💻
4
- colorFrom: pink
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 5.28.0
8
  app_file: app.py
9
- pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: gradio-pitch
 
 
 
 
 
3
  app_file: app.py
4
+ sdk: gradio
5
+ sdk_version: 3.50.2
6
  ---
 
 
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import librosa
3
+ import numpy as np
4
+ import soundfile as sf
5
+ import tempfile
6
+
7
+ def change_pitch(audio_file, pitch_shift):
8
+ # Load the audio file
9
+ y, sr = librosa.load(audio_file, sr=None)
10
+
11
+ # Apply pitch shifting
12
+ y_shifted = librosa.effects.pitch_shift(y=y, sr=sr, n_steps=pitch_shift)
13
+
14
+ # Save original and shifted audio for playback
15
+ original_path = tempfile.NamedTemporaryFile(delete=False, suffix=".wav").name
16
+ shifted_path = tempfile.NamedTemporaryFile(delete=False, suffix=".wav").name
17
+
18
+ sf.write(original_path, y, sr)
19
+ sf.write(shifted_path, y_shifted, sr)
20
+
21
+ return original_path, shifted_path
22
+
23
+ with gr.Blocks() as demo:
24
+ gr.Markdown("## 🎧 Audio Pitch Shifter")
25
+ gr.Markdown("Upload an audio file, choose how many semitones to shift the pitch, and listen to the result.")
26
+
27
+ with gr.Row():
28
+ audio_input = gr.Audio(type="filepath", label="Upload Audio")
29
+ pitch_slider = gr.Slider(-12, 12, value=0, step=1, label="Pitch Shift (semitones)")
30
+ submit_btn = gr.Button("Apply Pitch Shift")
31
+
32
+ with gr.Row():
33
+ original_audio = gr.Audio(label="Original Audio", interactive=False)
34
+ shifted_audio = gr.Audio(label="Pitch-Shifted Audio", interactive=False)
35
+
36
+ submit_btn.click(
37
+ fn=change_pitch,
38
+ inputs=[audio_input, pitch_slider],
39
+ outputs=[original_audio, shifted_audio]
40
+ )
41
+
42
+ if __name__ == "__main__":
43
+ # Fix: Add share=True to create a shareable link when localhost isn't accessible
44
+ demo.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ librosa
3
+ numpy
4
+ soundfile