Skip to content

Commit

Permalink
CapsTranser-Offline 分支新增 支持自动翻译为英文
Browse files Browse the repository at this point in the history
  • Loading branch information
H1DDENADM1N committed Feb 8, 2024
1 parent 23e9a9f commit 18a691d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ClientConfig:

file_seg_duration = 25 # 转录文件时分段长度
file_seg_overlap = 2 # 转录文件时分段重叠

translate = True # 自动翻译为英文

class ModelPaths:
model_dir = Path() / 'models'
Expand Down
9 changes: 8 additions & 1 deletion models/模型下载方式.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ https://github.com/HaujetZhao/CapsWriter-Offline/releases/tag/v1.0

从百度网盘下载打开模型:https://pan.baidu.com/s/1zNHstoWZDJVynCBz2yS9vg 提取码: eu4c

将两个模型文件夹 paraformer-offline-zh 和 punc_ct-transformer_cn-en 放到软件根目录的 models 文件夹中
将两个模型文件夹 paraformer-offline-zh 和 punc_ct-transformer_cn-en 放到软件根目录的 models 文件夹中


翻译模型:
https://huggingface.co/Helsinki-NLP/opus-mt-zh-en
https://object.pouta.csc.fi/Tatoeba-MT-models/zho-eng/opus-2020-07-17.zip

将翻译模型文件解压放到软件根目录的 models\Helsinki-NLP--opus-mt-zh-en\ 文件夹中
9 changes: 5 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@

1. 基于 [PySide6](https://pypi.org/project/PySide6/) 的 GUI,默认使用 [Qt-Material](https://github.com/UN-GCPDS/qt-material) dark_yellow 主题;基于 [PyStand](https://github.com/skywind3000/PyStand) 绿化便携 `start.exe`
2. 支持最小化到系统托盘。
3. ~~Server 和 Client 以 tab 集成在一个 gui,无任务栏占用。~~
4. ~~双击 start.exe 运行,可自行设置开机自启动~~ 不建议使用,参考[这里](https://github.com/HaujetZhao/CapsWriter-Offline/pull/53#issuecomment-1903681063)
3. Server 和 Client 以 tab 集成在一个 gui,无任务栏占用。
4. 双击 start.exe 运行,可自行设置开机自启动。
5. 已包含所有 Python 环境和 models 模型,解压即用。
6. 支持转录功能,将文件拖动到 `start_client_gui.exe`
7. `hint_while_recording.exe`跟随`start_client_gui.exe`启停,实现按下 Capslock 键会在光标处提示 [✦ 语音输入中‧‧‧](https://github.com/HaujetZhao/CapsWriter-Offline/issues/52#issuecomment-1905758203)
6. 支持转录功能,将文件拖动到 start_client_gui.exe
7. 按下 Capslock 键会在光标处提示 [✦ 语音输入中‧‧‧](https://github.com/HaujetZhao/CapsWriter-Offline/issues/52#issuecomment-1905758203)
8. CapsTranser-Offline 分支新增 支持自动翻译为英文,离线翻译模型[Helsinki-NLP/opus-mt-zh-en](https://huggingface.co/Helsinki-NLP/opus-mt-zh-en) , 默认启用,若不需要翻译,请修改`config.py` `translate = False`

下载地址:

Expand Down
12 changes: 12 additions & 0 deletions site-packages/运行依赖下载方式.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
从123盘下载发布包,并提权site-packages目录下依赖
https://www.123pan.com/s/qBxUVv-z1Zq3.html提取码:h8vb

离线翻译 Translate-Offline
https://www.123pan.com/s/qBxUVv-qYZq3.html 提取码:uGAy



Expand All @@ -11,9 +13,19 @@ https://www.123pan.com/s/qBxUVv-z1Zq3.html提取码:h8vb
方法二:
本地安装Python3.11.5虚拟环境(与runtime目录嵌入式Python版本保持一致)

离线语音输入 CapsWriter-Offline
pip install -r requirements-server.txt
pip install -r requirements-client.txt

图形化界面 gui
pip install PySide6
pip install qt-material

离线翻译 Translate-Offline
pip install torch
pip install flask
pip install gevent
pip install transformers
pip install sentencepice

将本地site-packages目录下依赖复制到此文件夹
30 changes: 28 additions & 2 deletions util/client_recv_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
from util.client_write_md import write_md
from util.client_type_result import type_result

from transformers import pipeline, AutoModelWithLMHead, AutoTokenizer
import warnings
warnings.filterwarnings ('ignore')

#翻译
if Config.translate:
modelName = ".\models\Helsinki-NLP--opus-mt-zh-en"
console.print('正在加载翻译模型......')
# 加载模型
model = AutoModelWithLMHead.from_pretrained(modelName, local_files_only=True)
# 加载分词器
tokenizer = AutoTokenizer.from_pretrained(modelName, local_files_only=True)
# 创建翻译管道
translation = pipeline('translation_zh_to_en', model=model, tokenizer=tokenizer)
console.print('翻译模型加载完成')


async def recv_result():
if not await check_websocket():
Expand All @@ -35,8 +51,9 @@ async def recv_result():
# 热词替换
text = hot_sub(text)

# 打字
await type_result(text)
# 翻译
if Config.translate:
trans_text = translation(text)[0]['translation_text']

if Config.save_audio:
# 重命名录音文件
Expand All @@ -48,8 +65,17 @@ async def recv_result():
# 控制台输出
console.print(f' 转录时延:{delay:.2f}s')
console.print(f' 识别结果:[green]{text}')
if Config.translate:
console.print(f' 翻译结果:[green]{trans_text}')
console.line()

# 打字
if Config.translate:
await type_result(trans_text)
else:
await type_result(text)


except websockets.ConnectionClosedError:
console.print('[red]连接断开\n')
except websockets.ConnectionClosedOK:
Expand Down

0 comments on commit 18a691d

Please sign in to comment.