import argparse import os import soundfile as sf from tools.i18n.i18n import I18nAuto from GPT_SoVITS.inference_webui import change_gpt_weights, change_sovits_weights, get_tts_wav i18n = I18nAuto() def synthesize(GPT_model_path, SoVITS_model_path, ref_audio_path, ref_text_path, ref_language, target_text, target_language, output_path, output_filename): # Read reference text with open(ref_text_path, 'r', encoding='utf-8') as file: ref_text = file.read() # Change model weights change_gpt_weights(gpt_path=GPT_model_path) change_sovits_weights(sovits_path=SoVITS_model_path) # Synthesize audio synthesis_result = get_tts_wav(ref_wav_path=ref_audio_path, prompt_text=ref_text, prompt_language=i18n(ref_language), text=target_text, text_language=i18n(target_language), top_p=1, temperature=1) result_list = list(synthesis_result) if result_list: last_sampling_rate, last_audio_data = result_list[-1] output_wav_path = os.path.join(output_path, output_filename) sf.write(output_wav_path, last_audio_data, last_sampling_rate) print(f"Audio saved to {output_wav_path}") def main(): GPT_model_path = "GPT_SoVITS/pretrained_models/gsv-v2final-pretrained/s1bert25hz-5kh-longer-epoch=12-step=369668.ckpt" SoVITS_model_path = "GPT_SoVITS/pretrained_models/gsv-v2final-pretrained/s2G2333k.pth" ref_audio_path = "/home/zydi//worker_chat/kafka/sample/woman.wav" ref_text_path = "/home/zydi//worker_chat/kafka/sample/woman.txt" ref_language = "中文" target_text = """我们开发了"病人实时健康监测系统"和"AI辅助诊断系统",这些系统显著提高了医疗诊断的效率和准确性。obscura形成了全面的医疗智能解决方案""" target_language = "多语种混合" output_path = "/home/zydi//worker_chat/kafka" output_filename = "output.wav" synthesize(GPT_model_path, SoVITS_model_path, ref_audio_path, ref_text_path, ref_language, target_text, target_language, output_path, output_filename) if __name__ == '__main__': main()