QQ扫一扫联系
需要掌握 python 开发能力
首先需要将python环境打包到同一个目录,比如 _aienv
,然后可以通过 python run.py ./config.json
的方式运行模型。
模型运行之后,通过标准输入输出的方式运行模型,通过标准输入传递参数,通过标准输出返回结果。
import json import base64 import shutil import sys import time import os # 解析输入配置文件 config = json.loads(open(sys.argv[1], 'r').read()) def cacheRandom(ext): cacheRoot = os.path.abspath('_cache') if not os.path.exists(cacheRoot): os.makedirs(cacheRoot) return os.path.join(cacheRoot, str(time.time()) + '.' + ext) def printResult(key, value): global config print('AigcPanelRunResult', {key: value}) print(f'AigcPanelRunResult[{config["id"]}][' + base64.b64encode(json.dumps({key: value}).encode()).decode() + ']') # 公共输出 ## 检测是否支持 Cuda 输出给前端 printResult('UseCuda', True) ########### 语音合成 ########### ## config = { "id": "SoundTts_999", "mode": "local", "modelConfig": { "type": "soundTts", "param": {}, "text": "你好" }, "setting": {} } if config['modelConfig']['type'] == 'soundTts': print('正在合成', 'config=', config) time.sleep(30) resultPath = cacheRandom('wav') shutil.copy('./example/nihao.wav', resultPath) print('合成完成', resultPath) ## 语音合成输出结果 printResult('url', resultPath) ########### 语音合成 ########### ########### 语音克隆 ########### ## config = { "id": "SoundClone_999", "mode": "local", "modelConfig": { "type": "soundClone", "param": {}, "text": "你好", "promptAudio": "/path/to/audio/xxxxx.wav", "promptText": "参考音频提示文字" }, "setting": {} } if config['modelConfig']['type'] == 'soundClone': print('正在克隆', 'config=', config) time.sleep(3) resultPath = cacheRandom('wav') shutil.copy('./example/nihao.wav', resultPath) print('克隆完成', resultPath) ## 语音克隆输出结果 printResult('url', resultPath) ########### 语音克隆 ########### ########### 视频合成 ########### ## config = { "id": "VideoGen_999", "mode": "local", "modelConfig": { "type": "videoGen", "param": {}, "video": "/path/to/video/xxxxx.mp4", "audio": "/path/to/audio/xxxxx.wav" }, "setting": {} } if config['modelConfig']['type'] == 'videoGen': print('正在生成', 'config=', config) time.sleep(3) resultPath = cacheRandom('mp4') shutil.copy('./example/short.mp4', resultPath) print('生成完成', resultPath) ## 视频合成输出结果 printResult('url', resultPath) ########### 视频合成 ###########
{ "name": "server-xxx", // 模型名称 "version": "0.1.0", // 模型版本 "title": "语音模型", // 模型标题 "description": "模型描述", // 模型描述 "deviceDescription":"设备描述", "platformName": "win", // 支持系统,win, osx, linux "platformArch": "x86", // 支持架构,x86, arm64 "serverRequire": ">=0.5.0", // 对 AigcPanel 版本的要求,如 >=0.5.0 "entry": "__EasyServer__", // 固定值,不需要修改 "easyServer": { // python 运行入口 // Windows ".\\_aienv\\python.ext" // MacOS/Linux "./_aienv/bin/python" "entry": "./_aienv/bin/python", "entryArgs": [ "run.py", "${CONFIG}" ], // 环境变量 "envs": [ "FOO=BAR" ] }, "functions": [ "videoGen", // 支持视频生成 "soundTTS", // 支持语音合成 "soundClone" // 支持语音克隆 ], "settings": [] }
完成两个文件的开发之后,在软件中尝试选择模型文件夹中的config.json导入。