本文由 资源共享网 – admin 发布,转载请注明出处,如有问题请联系我们!乐玩及其AARDIO调用插件
资源语言: 中文
在AARDIO里调用
var comx
registerLwDll = function(path ){
import com.lite;
comx = com.lite("D:\lw.dll");
comx.registerServer();
var instance = comx.createInstance("{F6C2EA3D-2A5A-4B63-AFDB-5E24BD1D39A0}");
lwDll = com.QueryObject(instance)
return lwDll;
}
unregisterLwDll = function(){
if(comx){
comx.unregisterServer();
}
}
test = function(){
lwdll = registerLwDll();
import io;
import com;
io.open();
var functions = com.DumpTypeInfo(lwdll)
io.print(com.DumpTypeInfo(lwDll))
io.print(lwDll.ver());
io.print(lwDll.getNetIp());
}
test();
unregisterLwDll();aardio调用python语言pyttsx3实现文字转语音功能
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};
edit2={cls=“edit”;text=“Edit”;left=60;top=334;right=548;bottom=434;edge=1;multiline=1;z=3}
)
/}}/
//aardio 执行 Python 代码
import process.python;
import console;
console.open();
var pyCode = /**
import sys
try:
import pyttsx3
except ImportError:
print(“请先安装 pyttsx3 模块:pip install pyttsx3”)
sys.exit(1)
def process_text(text):
return text
def init_engine():
engine = pyttsx3.init()
# 设置基本参数
engine.setProperty('rate', 150) # 设置语速 (范围一般在100-300之间)
engine.setProperty('volume', 0.9) # 设置音量 (范围为0.0-1.0)
return engine
def print_voice_info(engine):
# 获取并打印当前设置
rate = engine.getProperty(‘rate’)
volume = engine.getProperty(‘volume’)
# 查看可用声音
voices = engine.getProperty('voices')
for voice in voices:
print(f'声音ID:{voice.id}')
return voices
def save_to_mp3(text):
try:
engine = init_engine()
voices = engine.getProperty(‘voices’)
if voices:
selected_voice = voices[0]
engine.setProperty('voice', selected_voice.id)
# 生成文件名
import datetime
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"tts_{timestamp}.mp3"
# 播放并保存
engine.say(text)
engine.save_to_file(text, filename)
engine.runAndWait()
return filename
return None
except Exception as e:
print(f"错误:{str(e)}")
return None
if name == “main”:
text = sys.argv[1] # 获取命令行参数
result = save_to_mp3(text)
if result:
print(result) # 输出文件名供aardio获取
**/
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.edit2.text = fullPath; // 显示完整路径
}
if(python.stderr){
win.msgbox(python.stderr,"错误信息");
return;
}
}
catch(e){
win.msgbox(e.message,"执行异常");
}
}
winform.show();
win.loopMessage();

