import datetime import gradio as gr import numpy as np import os from paddlespeech.cli.tts.infer import TTSExecutor #该函数有3个输入参数和2个输出参数 def greet(name, file): print(file) #语音合成 wavname = f"{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}.wav" tts = TTSExecutor() tts(text=name, output=wavname) output_file = f"results/{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}.mp4" #处理视频 ckpt = os.path.join(os.path.dirname(__file__), "checkpoints/wav2lip.pth") audio = os.path.join(os.path.dirname(__file__), wavname) out = os.path.join(os.path.dirname(__file__), output_file) print(ckpt) print(audio) print(out) os.system(f"python3.10 ./inference.py --checkpoint_path {ckpt} --face_det_batch_size 1 --face {file} --audio {audio} --outfile={out}") # video_file = os.path.join(os.path.dirname(__file__), "result_voice5.mp4") # video_bytes = open(video_file, "rb").read() return wavname, out demo = gr.Interface( fn=greet, #按照处理程序设置输入组件 inputs=[gr.Text(placeholder="输入要转的文本"), gr.Image(type="filepath")], #按照处理程序设置输出组件 outputs=[gr.Audio(), gr.Video(label="Processed Video")], ) if __name__ == "__main__": demo.launch()