File size: 1,249 Bytes
e2a6087 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import gradio as gr
from transformers import pipeline
# Load the pre-trained voice conversion model
# You can replace with any RVC / voice conversion model from Hugging Face
vc_pipeline = pipeline("audio-to-audio", model="wok000/RVC-Hindi-Voice")
def convert_voice(input_audio):
# input_audio is a tuple: (sample_rate, numpy_array)
sr, data = input_audio
# Save the input to a temporary file for processing
input_path = "input.wav"
import soundfile as sf
sf.write(input_path, data, sr)
# Run voice conversion
result = vc_pipeline(input_path)
# The pipeline returns a dictionary with 'audio'
output_audio_path = "output.wav"
with open(output_audio_path, "wb") as f:
f.write(result["audio"])
return output_audio_path
# Gradio Interface
demo = gr.Interface(
fn=convert_voice,
inputs=gr.Audio(sources=["microphone", "upload"], type="numpy", label="Upload or Record Audio"),
outputs=gr.Audio(type="file", label="Converted Voice"),
title="Indian Accent Voice Conversion",
description="Upload a voice sample and convert it to a Hindi-styled accent using a pre-trained RVC model."
)
if __name__ == "__main__":
demo.launch()
|