File size: 2,038 Bytes
d6b40b1 |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import gradio as gr
import logging
import os
from TTS.api import TTS
import time
tts = TTS(model_name="voice_conversion_models/multilingual/vctk/freevc24", progress_bar=False, gpu=False)
logging.basicConfig(level=logging.INFO)
count = 0
def main():
global count
count += 1
if count > 50:
time.sleep(5)
os.system("rm -R /tmp/*")
count = 0
with gr.Blocks() as demo:
with gr.Row():
with gr.Column(variant="panel"):
src_audio_mic = gr.Audio(source="microphone", label="Record your voice")
src_audio_file = gr.Audio(
source="upload", type="filepath", label="Or upload audio to convert"
)
with gr.Column(variant="panel"):
tgt_audio_file = gr.Audio(
source="upload", type="filepath", label="Select audio with target voice"
)
with gr.Row():
convert_btn = gr.Button("Convert")
with gr.Row():
result_audio = gr.Audio()
def voice_conversion(src_from_mic_, src_from_file_, tgt_from_file_):
"""
helper function which checks where source come from
"""
src_ = None
if src_from_mic_:
src_ = src_from_mic_
elif src_from_file_:
src_ = src_from_file_
tgt_ = tgt_from_file_
if not src_ or not tgt_:
logging.warning("source or target are not provided")
return
print(src_)
print(tgt_)
tts.voice_conversion_to_file(source_wav=src_, target_wav=tgt_, file_path="output.wav")
return "output.wav"
convert_btn.click(
voice_conversion,
inputs=[src_audio_mic, src_audio_file, tgt_audio_file],
outputs=result_audio,
)
demo.queue(concurrency_count=1).launch(show_api=False, show_error=True)
if __name__ == "__main__":
main()
|