aardio调用python-edgetts库播放语音

redchina 6月前 602

初步实现了调用,能够调用aardio调用python-edgetts库播放语音还不完善

Code AardioLine:85复制
  • 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.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
    • import win.ui;
    • /*DSG{{*/
    • var winform = win.form(text="aardio form";right=759;bottom=469)
    • winform.add(
    • button={cls="button";text="Button";left=229;top=257;right=413;bottom=305;z=1};
    • edit={cls="edit";text="Edit";left=6;top=49;right=750;bottom=235;edge=1;multiline=1;z=2};
    • edit3={cls="edit";text="Edit";left=19;top=329;right=749;bottom=369;edge=1;multiline=1;z=3}
    • )
    • /*}}*/
    • //aardio 执行 Python 代码
    • import process.python;
    • import console;
    • console.open();
    • /*
    • import process.python.pip;
    • process.python.pip("install edge-tts");
    • */
    • var pyCode = /**
    • import asyncio
    • import sys
    • import edge_tts
    • def process_text(text):
    • return text
    • # 生成文件名
    • import datetime
    • timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
    • filename = f"tts_{timestamp}.mp3"
    • #TEXT = "大家好,欢迎关注pythontts项目。"
    • VOICE = "zh-CN-YunyangNeural"
    • #OUTPUT_FILE = "L:/aardio/project/调用python测试/test.mp3"
    • #调用edge_tts将文本转换为语音
    • text = sys.argv[1]
    • async def amain() -> None:
    • """Main function"""
    • communicate = edge_tts.Communicate(text, VOICE, rate="+10%")
    • await communicate.save(filename)
    • return filename
    • if __name__ == "__main__":
    • loop = asyncio.get_event_loop_policy().get_event_loop()
    • try:
    • loop.run_until_complete(amain())
    • finally:
    • loop.close()
    • **/
    • winform.edit.text = "aardio 是历经 20 年活跃更新的桌面软件开发工具";
    • winform.button.oncommand = function(id,event){
    • try{
    • var text = string.replace(winform.edit.text,'\"','\\"');
    • text = string.replace(text,'\r\n','\\n');
    • var python = process.python.exec(pyCode,text);
    • // 获取相对文件名
    • var filename = string.trim(python.readAll());
    • if(filename){
    • // 获取当前目录的完整路径
    • var fullPath = io.fullpath(filename);
    • winform.edit3.text = fullPath; // 显示完整路径
    • }
    • if(python.stderr){
    • win.msgbox(python.stderr,"错误信息");
    • return;
    • }
    • }
    • catch(e){
    • win.msgbox(e.message,"执行异常");
    • }
    • }
    • winform.show();
    • win.loopMessage();


    最新回复 (0)
    返回