Skip to content

Commit

Permalink
Ver3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
PantsuDango committed May 10, 2020
1 parent 7677d14 commit 16ac02e
Show file tree
Hide file tree
Showing 24 changed files with 129 additions and 39 deletions.
42 changes: 30 additions & 12 deletions API.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def get_Access_Token():
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=%s&client_secret=%s'%(client_id, client_secret)
try:
response = requests.get(host)

except TypeError:
print_exc()
MessageBox('文件路径错误', '请将翻译器目录的路径设置为纯英文\n否则无法在非简中区的电脑系统下运行使用')
return 0 # 返回失败标志

except Exception:
print_exc()
MessageBox('OCR错误', '啊咧... Σ(っ°Д°;)っ OCR连接失败惹 (つД`)\n请打开“网络和Internet设置”的代理页面\n将其中的全部代理设置开关都关掉呢 (˘•ω•˘)')
Expand Down Expand Up @@ -109,7 +115,7 @@ def baidu_orc(data):
if not access_token:
sentence = 'OCR连接失败:还未注册OCR API,不可使用'
error_stop()
return None
return None, sentence
else:
if showTranslateRow == 'True' or highPrecision == 'True':
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic" # 高精度
Expand All @@ -124,62 +130,74 @@ def baidu_orc(data):

try:
response = requests.post(request_url, data=params, headers=headers)

except TypeError:
print_exc()
sentence = '路径错误:请将翻译器目录的路径设置为纯英文,否则无法在非简中区的电脑系统下运行使用'
error_stop()
return None, sentence

except Exception:
print_exc()
sentence = 'OCR连接失败:请打开【网络和Internet设置】的【代理】页面,将其中的全部代理设置开关都关掉'
error_stop()
return None
return None, sentence
else:
if response:
try:
words = response.json()['words_result']
except Exception:
print_exc()
print()
error_code = response.json()["error_code"]
error_msg = response.json()["error_msg"]

if error_code == 6:
sentence = 'OCR错误:检查一下你的OCR注册网页,注册的类型是不是文字识别,你可能注册到语音技术还是其它什么奇怪的东西了'
error_stop()
return None
return None, sentence

elif error_code == 17:
sentence = 'OCR错误:OCR额度用光了,每天五万次的额度你是怎么用光的,是不是开着自动模式挂机呢?只有等明天再玩了'
error_stop()
return None
return None, sentence

elif error_code == 18:
baidu_orc(data)

elif error_code == 111:
sentence = 'OCR错误:密钥过期了,请进入设置页面后按一次保存设置,以重新生成密钥'
error_stop()
return None, sentence

elif error_code == 216202:
sentence = 'OCR错误:范围截取过小无法识别,请重新框选一下你要翻译的区域'
error_stop()
return None
return None, sentence

else:
sentence = 'OCR错误:%s,%s'%(error_code, error_msg)
error_stop()
return None
return None, sentence

else:
sentence = ''

# 竖排翻译模式
if showTranslateRow == 'True':
for word in words[::-1]:
sentence += word['words'] + ','
sentence = sentence.replace(',','')
if words:
for word in words[::-1]:
sentence += word['words'] + ','
sentence = sentence.replace(',','')

# 普通翻译模式
else:
for word in words:
sentence += word['words']

return sentence
return True, sentence
else:
return None
sentence = 'OCR错误:response无响应'
return None, sentence


# 有道翻译
Expand Down
29 changes: 18 additions & 11 deletions Init.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def init_ui(self):
self.format = QTextCharFormat()
self.format.setTextOutline(QPen(QColor('#FF69B4'), 0.7, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
self.translateText.mergeCurrentCharFormat(self.format)
self.translateText.append("团子翻译器 ver3.2 --- By:胖次团子 更新时间:2020-05-04")
self.translateText.append("团子翻译器 ver3.3 --- By:胖次团子 更新时间:2020-05-07")
self.translateText.append("交流群:1050705995 加群可获取最新版本并解惑翻译器一切问题")
self.translateText.append("喜欢这个软件可以点击上方的电池按钮给团子个充电支持吗 ❤")
self.translateText.append("团子会努力保持更新让大家用上更好的团子翻译器哒!")
Expand Down Expand Up @@ -353,7 +353,6 @@ def get_settin(self):
if self.horizontal == 0:
self.horizontal = 0.01


def start_login(self):

with open('.\\config\\settin.json') as file:
Expand All @@ -367,11 +366,6 @@ def start_login(self):
self.StartButton.setIcon(qtawesome.icon('fa.play', color='white'))
else:
try:
Font = QFont()
Font.setFamily(data["fontType"])
Font.setPointSize(data["fontSize"])
self.translateText.setFont(Font)

self.thread = Runthread(self, self.mode)
self.thread._signal.connect(self.call_backlog)
self.thread.start()
Expand All @@ -390,9 +384,11 @@ def call_backlog(self, result):
with open('.\\config\\settin.json') as file:
data = json.load(file)

if not result["original"]:
pass
else:
self.Font.setFamily(data["fontType"])
self.Font.setPointSize(data["fontSize"])
self.translateText.setFont(self.Font)

if result["original"] and result["sign"]:
self.original = result["original"]
self.translateText.clear()

Expand Down Expand Up @@ -499,7 +495,18 @@ def call_backlog(self, result):
self.translateText.append(result["youdao"])
else:
self.translateText.append("<font color=%s>%s</font>"%(data["fontColor"]["youdao"], result["youdao"]))


# 如果OCR出错,则打印错误信息
elif result["original"] and not result["sign"]:
self.translateText.clear()

if data["showColorType"] == "False":
self.format.setTextOutline(QPen(QColor(data["fontColor"]["original"]), 0.7, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
self.translateText.mergeCurrentCharFormat(self.format)
self.translateText.append(result["original"])
else:
self.translateText.append("<font color=%s>%s</font>"%(data["fontColor"]["original"], result["original"]))


# 语音朗读
def play_voice(self):
Expand Down
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Dango-Translator —— 团子翻译器
+ 目前最新版本:Ver3.3
+ 交流QQ群:1050705995(获取最新版本、翻译器交流、解惑)
+ 联系我:QQ 394883561 or [email protected]
+ 百度盘下载:https://pan.baidu.com/s/1B874q1S7OjtBZNHErvJ86A
+ 提取码:2d59
+ 解压密码:Dango

<br/>

### 效果截图:
#### 翻译界面:
![](https://github.com/PantsuDango/Dango-Translator/blob/master/git_image/Ver3.3/1.png)

#### 翻译效果(翻译源为彩云小泽):
![](https://github.com/PantsuDango/Dango-Translator/blob/master/git_image/Ver3.3/2.png)

#### 设置-API设定:
![](https://github.com/PantsuDango/Dango-Translator/blob/master/git_image/Ver3.3/3.png)

#### 设置-翻译源:
![](https://github.com/PantsuDango/Dango-Translator/blob/master/git_image/Ver3.3/4.png)

#### 设置-翻译样式:
![](https://github.com/PantsuDango/Dango-Translator/blob/master/git_image/Ver3.3/5.png)

#### 设置-其他设定:
![](https://github.com/PantsuDango/Dango-Translator/blob/master/git_image/Ver3.3/6.png)

<br/>

### 为什么想制作这个:
本身是个vnr翻译软件的忠实用户,但是遇到某些游戏无法提取文本,并且没有找到有热心人公开发布的特殊码,于是某天研究如何提取特殊码研究到了深夜还是失败了。然后发现有OCR(文字识别)技术的存在,下载了很多已经有的OCR翻译器,但是使用体验都觉得很不方便,于是萌生了自己制作一个自己喜欢的翻译器的想法

<br/>

### 简单地说明:
+ 原理:该软件为OCR翻译器,OCR利用了百度AI的文字识别,原理为通过识别图片上的外文文字并进行翻译;
+ 适用范围:包括但不限于,galgame、rpg游戏、模拟器游戏、外文视频、网页游戏、pdf图片版文献等等,一切能显示在电脑屏幕上的文字;
+ 翻译接口:百度、腾讯、彩云、google等等共12个翻译源;
+ 译文语种:日语、英语、韩文(会考虑加入其它的,但是目前必要性不大);
+ 其它详细情况参见软件版内配置的使用教程;

<br/>

### 功能流程:
+ 通过截图的方式获取需要翻译的屏幕区域坐标;
+ 通过坐标截图(可自动),并发送至百度AI的文字识别接口;
+ 获取识别好的文字后发送给百度、腾讯、彩云等翻译接口;
+ 结果反馈至GUI界面;

<br/>

### 功能比较多,还请自行下载体会 ヾ(๑╹◡╹)ノ"

<br/>
5 changes: 2 additions & 3 deletions Settin.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ def setupUi(self):
self.Mysay_label = QtWidgets.QLabel(self.tab_5)
self.Mysay_label.setGeometry(QtCore.QRect(40*self.rate, 10*self.rate, 281*self.rate, 141*self.rate))
self.Mysay_label.setText("<html><head/><body><p>大家好,我是胖次团子 ❤\
</p><p>谢谢大家使用团子翻译器Ver3.2 ~\
</p><p>谢谢大家使用团子翻译器Ver3.3 ~\
</p><p>软件是免费的,但是若能收到你的充电支持 ~\
</p><p>我会非常开心的,这会是我后续更新的动力 ~\
</p><p>联系方式 ———— QQ 394883561</p></body></html>")
Expand All @@ -750,14 +750,13 @@ def setupUi(self):
self.SaveButton = QtWidgets.QPushButton(self)
self.SaveButton.setGeometry(QtCore.QRect(85*self.rate, 515*self.rate, 90*self.rate, 30*self.rate))
self.SaveButton.setStyleSheet("background: rgba(255, 255, 255, 0.4);font: 12pt;")
self.SaveButton.clicked.connect(self.save_settin)
self.SaveButton.setText("保存设置")

# 设置返回按钮
self.CancelButton = QtWidgets.QPushButton(self)
self.CancelButton.setGeometry(QtCore.QRect(232*self.rate, 515*self.rate, 90*self.rate, 30*self.rate))
self.CancelButton.setStyleSheet("background: rgba(255, 255, 255, 0.4);font: 12pt")
self.CancelButton.setText("返 回")
self.CancelButton.setText("退 出")


def get_settin(self): # 获取所有预设值
Expand Down
Binary file modified __pycache__/API.cpython-35.pyc
Binary file not shown.
Binary file removed __pycache__/Bing.cpython-35.pyc
Binary file not shown.
Binary file removed __pycache__/Google.cpython-35.pyc
Binary file not shown.
Binary file removed __pycache__/Init.cpython-35.pyc
Binary file not shown.
Binary file removed __pycache__/Range.cpython-35.pyc
Binary file not shown.
Binary file modified __pycache__/ScreenRate.cpython-35.pyc
Binary file not shown.
Binary file removed __pycache__/Settin.cpython-35.pyc
Binary file not shown.
Binary file removed __pycache__/Tencent.cpython-35.pyc
Binary file not shown.
Binary file removed __pycache__/Translate.cpython-35.pyc
Binary file not shown.
Binary file removed __pycache__/baidufanyi.cpython-35.pyc
Binary file not shown.
Binary file removed __pycache__/hotKey.cpython-35.pyc
Binary file not shown.
Binary file modified __pycache__/image.cpython-35.pyc
Binary file not shown.
Binary file removed __pycache__/playVoice.cpython-35.pyc
Binary file not shown.
Binary file removed __pycache__/switch.cpython-35.pyc
Binary file not shown.
Binary file modified config/image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion config/settin.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"tencentAPI": {"Secret": "", "Key": ""}, "showOriginal": "False", "highPrecision": "False", "fontColor": {"google": "#ff55ff", "original": "#ff55ff", "Bing": "#ff55ff", "tencent": "#ff55ff", "yeekit": "#ff55ff", "baidu": "#ff55ff", "tencentweb": "#ff55ff", "youdao": "#ff55ff", "jinshan": "#ff55ff", "caiyunPrivate": "#ff55ff", "ALAPI": "#ff55ff", "baiduweb": "#ff55ff", "caiyun": "#ff55ff"}, "alapiUse": "False", "yeekitUse": "False", "showHotKey2": "False", "range": {"Y1": 590, "Y2": 741, "X1": 210, "X2": 1097}, "caiyunAPI": "", "showColorType": "False", "yeekitLanguage": "nja", "language": "JAP", "caiyunPrivateUse": "False", "OCR": {"Secret": "", "Key": ""}, "tencentwebUse": "False", "googleUse": "False", "baiduUse": "False", "translateSpeed": 1.0, "fontSize": 15, "fontType": "\u534e\u5eb7\u65b9\u5706\u4f53W7", "showHotKeyValue1": "F1", "youdaoUse": "False", "BingUse": "False", "showHotKeyValue2": "F2", "baiduAPI": {"Secret": "", "Key": ""}, "showClipboard": "False", "caiyunUse": "False", "showHotKey1": "False", "translateMode": "auto", "AccessToken": "", "jinshanUse": "False", "baiduwebUse": "False", "horizontal": 0, "BingLanguage": "ja", "tencentUse": "False", "sign": 1, "showTranslateRow": "False"}
{"youdaoUse": "False", "BingLanguage": "ja", "sign": 1, "showOriginal": "False", "range": {"Y2": 412, "X1": 1785, "Y1": 315, "X2": 1919}, "showClipboard": "False", "showTranslateRow": "False", "fontType": "\u534e\u5eb7\u65b9\u5706\u4f53W7", "baiduUse": "False", "alapiUse": "False", "showHotKeyValue1": "F1", "AccessToken": "", "tencentwebUse": "False", "googleUse": "False", "showHotKeyValue2": "F2", "translateMode": "auto", "fontSize": 15, "baiduwebUse": "False", "tencentUse": "False", "fontColor": {"yeekit": "#ff55ff", "youdao": "#ff55ff", "caiyun": "#ff55ff", "tencent": "#ff55ff", "caiyunPrivate": "#ff55ff", "ALAPI": "#ff55ff", "tencentweb": "#ff55ff", "jinshan": "#ff55ff", "baiduweb": "#ff55ff", "Bing": "#ff55ff", "google": "#ff55ff", "baidu": "#ff55ff", "original": "#ff55ff"}, "tencentAPI": {"Secret": "", "Key": ""}, "yeekitUse": "False", "showHotKey1": "False", "translateSpeed": 1.0, "jinshanUse": "False", "caiyunUse": "False", "OCR": {"Secret": "", "Key": ""}, "horizontal": 0, "caiyunAPI": "", "highPrecision": "False", "showHotKey2": "False", "caiyunPrivateUse": "False", "baiduAPI": {"Secret": "", "Key": ""}, "yeekitLanguage": "nja", "language": "JAP", "showColorType": "False", "BingUse": "False"}
Binary file modified config/voice.mp3
Binary file not shown.
15 changes: 10 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ def goto_settin(self):
# 改变翻译键的图标为停止图标
self.Init.StartButton.setIcon(qtawesome.icon('fa.play', color='white'))

self.Init.close() # 关闭翻译界面
#self.Init.close() # 关闭翻译界面
self.Settin.tabWidget.setCurrentIndex(0) # 预设设置页面的初始为第一栏
self.Settin.show() # 打开设置页面


# 刷新主界面
def updata_Init(self):

self.Settin.close() # 关闭设置页面
#self.Settin.close() # 关闭设置页面
self.Settin.save_settin() # 保存设置
self.open_settin()

# 刷新翻译界面的背景透明度
Expand All @@ -106,6 +107,7 @@ def updata_Init(self):
font-weight: bold;\
background-color:rgba(62, 62, 62, %s)"
%(horizontal))

# 是否注销翻译键快捷键
if self.id_translate:
self.hotKey.removeHotkey(id=self.id_translate)
Expand All @@ -119,7 +121,7 @@ def updata_Init(self):
if self.data["showHotKey2"] == "True":
self.id_range = self.hotKey.addHotkey([self.data["showHotKeyValue2"]], self.goto_range)

self.Init.show() # 打开翻译界面
#self.Init.show() # 打开翻译界面


# 进入充电界面
Expand Down Expand Up @@ -172,12 +174,15 @@ def main(self):
self.Init.SettinButton.clicked.connect(self.goto_settin)
# 点击范围键后执行的函数
self.Init.RangeButton.clicked.connect(self.goto_range)
# 点击设置页面的返回键后执行的函数
self.Settin.CancelButton.clicked.connect(self.updata_Init)
# 点击充电键后执行的函数
self.Init.BatteryButton.clicked.connect(self.goto_Battery)
# 点击退出键后执行的函数
self.Init.QuitButton.clicked.connect(self.close)

# 点击设置页面的保存键后执行的函数
self.Settin.SaveButton.clicked.connect(self.updata_Init)
# 点击设置页面的退出键后执行的函数
self.Settin.CancelButton.clicked.connect(self.Settin.close)

App.exit(App.exec_())
self.hotKey.end()
Expand Down
4 changes: 3 additions & 1 deletion playVoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from playsound import playsound
from traceback import print_exc
import json

from js2py import EvalJs


Expand Down Expand Up @@ -38,6 +37,9 @@ def getTk(self):

def play_voice(self):




with open('.\\config\\settin.json') as file:
data = json.load(file)

Expand Down
15 changes: 9 additions & 6 deletions translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def translate(window, data):

text = window.translateText.toPlainText()
if text[:5] == "团子翻译器" or (not text[:1]):
score = 0.98
score = 0.97
image_cut(window, data)
else:
imageA = imread('.\\config\\image.jpg')
Expand All @@ -62,12 +62,13 @@ def translate(window, data):
try:
score = compare_image(imageA, imageB)
except Exception:
score = 0.98
score = 0.97

if score < 0.99:
if score < 0.98:

original = baidu_orc(data)
if original and (original != window.original):
sign, original = baidu_orc(data)

if sign and original and (original != window.original):

# 过滤不需要加入翻译的字符
try:
Expand Down Expand Up @@ -179,7 +180,7 @@ def translate(window, data):
result_baidu = ''
result_tencent = ''
result_caiyunPrivate = ''
original = ''

else:
result_youdao = ''
result_caiyun = ''
Expand All @@ -194,6 +195,7 @@ def translate(window, data):
result_tencent = ''
result_caiyunPrivate = ''
original = ''
sign = True

result = dict()
result["youdao"] = result_youdao
Expand All @@ -209,5 +211,6 @@ def translate(window, data):
result["tencent"] = result_tencent
result["caiyunPrivate"] = result_caiyunPrivate
result["original"] = original
result["sign"] = sign

return result

0 comments on commit 16ac02e

Please sign in to comment.