Spaces:
Runtime error
Runtime error
import gradio as gr | |
import librosa | |
import soundfile as sf | |
def nightcore_effect(audio_filepath): | |
try: | |
y, sr = librosa.load(audio_filepath, sr=None) | |
# Speed up the audio (e.g., 1.25 times faster) | |
y_speed_up = librosa.effects.time_stretch(y, rate=1.25) | |
# Shift the pitch higher (e.g., by 5 semitones) | |
y_pitch_shift = librosa.effects.pitch_shift(y_speed_up, sr=sr, n_steps=5) | |
# Save the modified audio to a temporary file | |
output_path = "modified_audio.wav" | |
sf.write(output_path, y_pitch_shift, sr) | |
return output_path | |
except Exception as e: | |
print(f"Error processing audio: {e}") | |
return "Error" | |
# Define the Gradio interface | |
iface = gr.Interface( | |
fn=nightcore_effect, | |
inputs=gr.Audio(type="filepath", label="Upload a .wav file"), # Updated line | |
outputs=gr.Audio(label="Processed Audio"), | |
live=False | |
) | |
# Launch the interface | |
iface.launch() | |