| 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() | |