import asyncio async def generate_speech(text, output_path): try: print(f"正在生成语音: '{text}'...") process = await asyncio.create_subprocess_exec( "edge-tts", "--text", text, "--voice", "zh-CN-XiaoxiaoNeural", "--rate", "+20%", # 语速加快 20% "--pitch", "+10%", # 音调略高,增强可爱感 "--write-media", output_path, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, ) await process.wait() # 等待合成完成 print(f"语音已保存到: {output_path}") except Exception as e: print(f"生成语音时出错: {e}") async def main(): await generate_speech("你好呀,我是小晓!", "/var/pyp/output.mp3") if __name__ == "__main__": asyncio.run(main()) # 正确启动异步任务