aardio调用python-edgetts库播放语音

redchina 4天前 82

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

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)
返回