Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
import librosa
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Assuming you have a model file for voice conversion
|
7 |
+
from model import load_model, convert_voice
|
8 |
+
|
9 |
+
# Load the pre-trained voice conversion model
|
10 |
+
model = load_model("path_to_pretrained_model") # Adjust this based on the actual RVC model
|
11 |
+
|
12 |
+
def voice_conversion(source_audio, target_voice):
|
13 |
+
"""
|
14 |
+
Function to perform voice conversion from source to target voice style
|
15 |
+
"""
|
16 |
+
# Convert input audio to the desired format (this may vary depending on your model)
|
17 |
+
y, sr = librosa.load(source_audio)
|
18 |
+
input_audio = torch.tensor(y).unsqueeze(0)
|
19 |
+
|
20 |
+
# Use model for voice conversion
|
21 |
+
converted_audio = convert_voice(model, input_audio, target_voice)
|
22 |
+
|
23 |
+
# Convert output tensor back to numpy for playback
|
24 |
+
converted_audio_np = converted_audio.detach().cpu().numpy()
|
25 |
+
|
26 |
+
# Save to file or return as numpy array
|
27 |
+
output_file = "output_converted.wav"
|
28 |
+
librosa.output.write_wav(output_file, converted_audio_np, sr)
|
29 |
+
|
30 |
+
return output_file
|
31 |
+
|
32 |
+
# Define the Gradio interface
|
33 |
+
def infer(source_audio, target_voice):
|
34 |
+
# Call the voice conversion function
|
35 |
+
result_audio = voice_conversion(source_audio, target_voice)
|
36 |
+
return result_audio
|
37 |
+
|
38 |
+
# Gradio interface with inputs and outputs
|
39 |
+
iface = gr.Interface(
|
40 |
+
fn=infer,
|
41 |
+
inputs=[
|
42 |
+
gr.Audio(source="microphone", type="filepath", label="Source Audio"),
|
43 |
+
gr.Dropdown(["Voice1", "Voice2", "Voice3"], label="Target Voice") # Dropdown for target voice options
|
44 |
+
],
|
45 |
+
outputs=gr.Audio(type="file", label="Converted Audio"),
|
46 |
+
title="Retrieval-based Voice Conversion",
|
47 |
+
description="Convert voice from a source audio to a target voice style."
|
48 |
+
)
|
49 |
+
|
50 |
+
if __name__ == "__main__":
|
51 |
+
iface.launch()
|