mirror of
https://github.com/HiMeditator/auto-caption.git
synced 2026-02-04 04:14:42 +08:00
- 添加 Ollama 大模型翻译和 Google 翻译(非实时),支持多种语言 - 为 Vosk 引擎添加非实时翻译 - 为新增的翻译功能添加和修改接口 - 修改 Electron 构建配置,之后不同平台构建无需修改构建文件
2.2 KiB
2.2 KiB
caption engine api-doc
本文档主要介绍字幕引擎和 Electron 主进程进程的通信约定。
原理说明
本项目的 Python 进程通过标准输出向 Electron 主进程发送数据。Python 进程标准输出 (sys.stdout) 的内容一定为一行一行的字符串。且每行字符串均可以解释为一个 JSON 对象。每个 JSON 对象一定有 command 参数。
Electron 主进程通过 TCP Socket 向 Python 进程发送数据。发送的数据均是转化为字符串的对象,对象格式一定为:
{
command: string,
content: string
}
标准输出约定
数据传递方向:字幕引擎进程 => Electron 主进程
当 JSON 对象的 command 参数为下列值时,表示的对应的含义:
connect
{
command: "connect",
content: ""
}
字幕引擎 TCP Socket 服务已经准备好,命令 Electron 主进程连接字幕引擎 Socket 服务
kill
{
command: "connect",
content: ""
}
命令 Electron 主进程强制结束字幕引擎进程。
caption
{
command: "caption",
index: number,
time_s: string,
time_t: string,
text: string,
translation: string
}
Python 端监听到的音频流转换为的字幕数据。
translation
{
command: "translation",
time_s: string,
translation: string
}
语音识别的内容的翻译,可以根据起始时间确定对应的字幕。
print
{
command: "print",
content: string
}
输出 Python 端打印的内容,不计入日志。
info
{
command: "info",
content: string
}
Python 端打印的提示信息,会计入日志。
error
{
command: "error",
content: string
}
Python 端打印的错误信息,该错误信息需要在前端弹窗显示。
usage
{
command: "usage",
content: string
}
Gummy 字幕引擎结束时打印计费消耗信息。
TCP Socket
数据传递方向:Electron 主进程 => 字幕引擎进程
当 JSON 对象的 command 参数为下列值时,表示的对应的含义:
stop
{
command: "stop",
content: ""
}
命令当前字幕引擎停止监听并结束任务。