mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
fix
This commit is contained in:
parent
bd04bd443b
commit
6f0132a166
@ -1,4 +1,4 @@
|
||||
from myutils.config import globalconfig, static_data
|
||||
from myutils.config import getlangsrc
|
||||
import requests
|
||||
from urllib.parse import quote
|
||||
import re
|
||||
@ -11,7 +11,7 @@ class youdao(cishubase):
|
||||
def srclang(self):
|
||||
|
||||
try:
|
||||
l = static_data["language_list_translator_inner"][globalconfig["srclang3"]]
|
||||
l = getlangsrc()
|
||||
return l
|
||||
|
||||
except:
|
||||
|
@ -1,5 +1,5 @@
|
||||
import os
|
||||
from myutils.config import globalconfig, _TRL, static_data
|
||||
from myutils.config import globalconfig, _TRL, static_data,getlanguse
|
||||
from gui.usefulwidget import getsimplecombobox, getcolorbutton
|
||||
|
||||
|
||||
@ -46,11 +46,7 @@ def setTablanglz(self):
|
||||
"",
|
||||
callback=lambda: os.startfile(
|
||||
os.path.abspath(
|
||||
"./files/lang/{}.json".format(
|
||||
static_data["language_list_translator_inner"][
|
||||
globalconfig["languageuse"]
|
||||
]
|
||||
)
|
||||
"./files/lang/{}.json".format(getlanguse())
|
||||
)
|
||||
),
|
||||
icon="fa.gear",
|
||||
|
@ -44,14 +44,14 @@ class AnkiWindow(QWidget):
|
||||
|
||||
def langdu(self):
|
||||
if gobject.baseobject.reader:
|
||||
self.audiopath.setText(
|
||||
gobject.baseobject.reader.syncttstofile(self.currentword)
|
||||
gobject.baseobject.reader.ttscallback(
|
||||
self.currentword, self.audiopath.setText
|
||||
)
|
||||
|
||||
def langdu2(self):
|
||||
if gobject.baseobject.reader:
|
||||
self.audiopath_sentence.setText(
|
||||
gobject.baseobject.reader.syncttstofile(self.example.toPlainText())
|
||||
gobject.baseobject.reader.ttscallback(
|
||||
self.example.toPlainText(), self.audiopath_sentence.setText
|
||||
)
|
||||
|
||||
@threader
|
||||
@ -205,27 +205,41 @@ class AnkiWindow(QWidget):
|
||||
|
||||
def loadfakefields(self):
|
||||
if len(self.editpath.text()):
|
||||
try:
|
||||
with open(self.editpath.text(), "rb") as image_file:
|
||||
encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
|
||||
encoded_string = '<img src="data:image/png;base64,{}">'.format(
|
||||
encoded_string
|
||||
)
|
||||
except:
|
||||
encoded_string = ""
|
||||
else:
|
||||
encoded_string = ""
|
||||
if len(self.audiopath.text()):
|
||||
try:
|
||||
with open(self.audiopath.text(), "rb") as image_file:
|
||||
encoded_string2 = base64.b64encode(image_file.read()).decode("utf-8")
|
||||
encoded_string2 = base64.b64encode(image_file.read()).decode(
|
||||
"utf-8"
|
||||
)
|
||||
encoded_string2 = """<button onclick='document.getElementById("audio1111").play()'>play audio<audio controls id="audio1111" style="display: none"><source src="data:audio/mpeg;base64,{}"></audio></button>""".format(
|
||||
encoded_string2
|
||||
)
|
||||
except:
|
||||
encoded_string2 = ""
|
||||
else:
|
||||
encoded_string2 = ""
|
||||
if len(self.audiopath_sentence.text()):
|
||||
try:
|
||||
with open(self.audiopath_sentence.text(), "rb") as image_file:
|
||||
encoded_string3 = base64.b64encode(image_file.read()).decode("utf-8")
|
||||
encoded_string3 = base64.b64encode(image_file.read()).decode(
|
||||
"utf-8"
|
||||
)
|
||||
encoded_string3 = """<button onclick='document.getElementById("audio2222").play()'>play audio_sentence<audio controls id="audio2222" style="display: none"><source src="data:audio/mpeg;base64,{}"></audio></button>""".format(
|
||||
encoded_string3
|
||||
)
|
||||
except:
|
||||
|
||||
encoded_string3 = ""
|
||||
else:
|
||||
encoded_string3 = ""
|
||||
fields = {
|
||||
|
@ -1,5 +1,5 @@
|
||||
from myutils.proxy import getproxy
|
||||
from myutils.config import globalconfig, _TR, static_data
|
||||
from myutils.config import getlangtgt, _TR, static_data, getlangsrc
|
||||
from myutils.wrapper import stripwrapper
|
||||
import requests
|
||||
|
||||
@ -34,7 +34,7 @@ class commonbase:
|
||||
@property
|
||||
def srclang(self):
|
||||
try:
|
||||
l = static_data["language_list_translator_inner"][globalconfig["srclang3"]]
|
||||
l = getlangsrc()
|
||||
return self.langmap_[l]
|
||||
except:
|
||||
return ""
|
||||
@ -42,7 +42,7 @@ class commonbase:
|
||||
@property
|
||||
def tgtlang(self):
|
||||
try:
|
||||
l = static_data["language_list_translator_inner"][globalconfig["tgtlang3"]]
|
||||
l = getlangtgt()
|
||||
return self.langmap_[l]
|
||||
except:
|
||||
return ""
|
||||
|
@ -187,14 +187,22 @@ if len(globalconfig["toolbutton"]["rank"]) != len(
|
||||
)
|
||||
|
||||
|
||||
def getlanguse():
|
||||
global language, languageshow
|
||||
return static_data["language_list_translator_inner"][language]
|
||||
|
||||
def getlangsrc():
|
||||
return static_data["language_list_translator_inner"][globalconfig["srclang3"]]
|
||||
|
||||
def getlangtgt():
|
||||
return static_data["language_list_translator_inner"][globalconfig["tgtlang3"]]
|
||||
|
||||
def setlanguage():
|
||||
global language, languageshow
|
||||
language = globalconfig["languageuse"]
|
||||
try:
|
||||
with open(
|
||||
"./files/lang/{}.json".format(
|
||||
static_data["language_list_translator_inner"][language]
|
||||
),
|
||||
"./files/lang/{}.json".format(getlanguse()),
|
||||
"r",
|
||||
encoding="utf8",
|
||||
) as ff:
|
||||
@ -255,8 +263,6 @@ def saveallconfig():
|
||||
"./userconfig/savehook_new_1.39.4.json", [savehook_new_list, savehook_new_data]
|
||||
)
|
||||
safesave(
|
||||
"./files/lang/{}.json".format(
|
||||
static_data["language_list_translator_inner"][language]
|
||||
),
|
||||
"./files/lang/{}.json".format(getlanguse()),
|
||||
languageshow,
|
||||
)
|
||||
|
@ -7,7 +7,7 @@ from myutils.config import (
|
||||
postprocessconfig,
|
||||
globalconfig,
|
||||
savehook_new_data,
|
||||
static_data,
|
||||
getlangsrc,
|
||||
)
|
||||
|
||||
|
||||
@ -179,7 +179,7 @@ def _4_f(line):
|
||||
|
||||
|
||||
def _6_fEX(line):
|
||||
srclang = static_data["language_list_translator_inner"][globalconfig["srclang3"]]
|
||||
srclang = getlangsrc()
|
||||
if srclang in ["zh", "ja"]:
|
||||
white = ""
|
||||
else:
|
||||
|
@ -15,6 +15,7 @@ from traceback import print_exc
|
||||
from myutils.config import (
|
||||
globalconfig,
|
||||
static_data,
|
||||
getlanguse,
|
||||
savehook_new_list,
|
||||
savehook_new_data,
|
||||
getdefaultsavehook,
|
||||
@ -537,10 +538,6 @@ def parsemayberegexreplace(dict, res):
|
||||
return res
|
||||
|
||||
|
||||
def getlanguse():
|
||||
return static_data["language_list_translator_inner"][globalconfig["languageuse"]]
|
||||
|
||||
|
||||
def checkpostlangmatch(name):
|
||||
for item in static_data["transoptimi"]:
|
||||
if name == item["name"]:
|
||||
|
@ -1,5 +1,5 @@
|
||||
import os
|
||||
from myutils.config import globalconfig, _TR, static_data
|
||||
from myutils.config import globalconfig, _TR, getlangsrc
|
||||
from ocrengines.baseocrclass import baseocr
|
||||
from ctypes import (
|
||||
CDLL,
|
||||
@ -131,9 +131,7 @@ class OCR(baseocr):
|
||||
return
|
||||
self._ocr.trydestroy()
|
||||
|
||||
path = "./files/ocr/{}".format(
|
||||
static_data["language_list_translator_inner"][globalconfig["srclang3"]]
|
||||
)
|
||||
path = "./files/ocr/{}".format(getlangsrc())
|
||||
if not (
|
||||
os.path.exists(path + "/det.onnx")
|
||||
and os.path.exists(path + "/rec.onnx")
|
||||
|
@ -1,7 +1,7 @@
|
||||
from traceback import print_exc
|
||||
from queue import Queue
|
||||
|
||||
from myutils.config import globalconfig, translatorsetting, static_data
|
||||
from myutils.config import globalconfig, translatorsetting, getlangtgt
|
||||
from threading import Thread
|
||||
import time, types
|
||||
import zhconv, gobject
|
||||
@ -172,7 +172,7 @@ class basetrans(commonbase):
|
||||
@property
|
||||
def needzhconv(self):
|
||||
# The API does not support direct translation to Traditional Chinese, only Simplified Chinese can be translated first and then converted to Traditional Chinese
|
||||
l = static_data["language_list_translator_inner"][globalconfig["tgtlang3"]]
|
||||
l = getlangtgt()
|
||||
return l == "cht" and "cht" not in self.langmap()
|
||||
|
||||
@property
|
||||
|
@ -1,6 +1,7 @@
|
||||
from myutils.config import globalconfig
|
||||
import threading, os
|
||||
|
||||
import threading, os, functools
|
||||
from myutils.wrapper import threader
|
||||
from traceback import print_exc
|
||||
|
||||
class TTSbase:
|
||||
def init(self):
|
||||
@ -19,7 +20,7 @@ class TTSbase:
|
||||
# 一些可能需要的属性
|
||||
@property
|
||||
def config(self):
|
||||
return self.privateconfig['args']
|
||||
return self.privateconfig["args"]
|
||||
|
||||
@property
|
||||
def privateconfig(self):
|
||||
@ -28,6 +29,7 @@ class TTSbase:
|
||||
@property
|
||||
def publicconfig(self):
|
||||
return globalconfig["ttscommon"]
|
||||
|
||||
########################
|
||||
|
||||
def __init__(self, typename, showlistsignal, mp3playsignal) -> None:
|
||||
@ -58,15 +60,14 @@ class TTSbase:
|
||||
threading.Thread(target=_).start()
|
||||
|
||||
def read(self, content, force=False):
|
||||
def _(content, force):
|
||||
fname = self.syncttstofile(content)
|
||||
def _(force, fname):
|
||||
volume = self.publicconfig["volume"]
|
||||
if fname:
|
||||
self.mp3playsignal.emit(fname, volume, force)
|
||||
|
||||
threading.Thread(target=_, args=(content, force)).start()
|
||||
self.ttscallback(content, functools.partial(_, force))
|
||||
|
||||
def syncttstofile(self, content):
|
||||
@threader
|
||||
def ttscallback(self, content, callback):
|
||||
if self.loadok == False:
|
||||
return
|
||||
if len(content) == 0:
|
||||
@ -77,5 +78,10 @@ class TTSbase:
|
||||
rate = self.publicconfig["rate"]
|
||||
voice = self.privateconfig["voice"]
|
||||
voice_index = self.voicelist.index(voice)
|
||||
try:
|
||||
fname = self.speak(content, rate, voice, voice_index)
|
||||
return os.path.abspath(fname)
|
||||
if fname:
|
||||
callback(os.path.abspath(fname))
|
||||
except:
|
||||
print_exc()
|
||||
return
|
||||
|
1093
LunaTranslator/LunaTranslator/tts/gtts.py
Normal file
1093
LunaTranslator/LunaTranslator/tts/gtts.py
Normal file
File diff suppressed because it is too large
Load Diff
@ -24,7 +24,6 @@ class TTS(TTSbase):
|
||||
|
||||
def speak(self, content, rate, voice, voiceidx):
|
||||
|
||||
try:
|
||||
headers = {
|
||||
"authority": "translate.volcengine.com",
|
||||
"accept": "application/json, text/plain, */*",
|
||||
@ -53,7 +52,3 @@ class TTS(TTSbase):
|
||||
ff.write(b64)
|
||||
|
||||
return "./cache/tts/" + fname + ".mp3"
|
||||
|
||||
except:
|
||||
print_exc()
|
||||
return None
|
||||
|
@ -126,7 +126,7 @@ class TTS(TTSbase):
|
||||
def speak(self, content, rate, voice, voice_idx):
|
||||
self.checkpath()
|
||||
# def _():
|
||||
if True:
|
||||
|
||||
|
||||
try:
|
||||
content.encode("shift-jis")
|
||||
|
@ -115,8 +115,7 @@ class TTS(TTSbase):
|
||||
|
||||
def speak(self, content, rate, voice, voice_idx):
|
||||
self.checkpath()
|
||||
# def _():
|
||||
if True:
|
||||
|
||||
|
||||
try:
|
||||
content.encode("shift-jis")
|
||||
|
@ -74,9 +74,6 @@ class TTS(TTSbase):
|
||||
|
||||
def speak(self, content, rate, voice, voiceidx):
|
||||
|
||||
# def _():
|
||||
if True:
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}
|
||||
|
@ -725,6 +725,11 @@
|
||||
"name": "GPT-SOVITS preset"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gtts": {
|
||||
"use": false,
|
||||
"name": "谷歌",
|
||||
"voice": ""
|
||||
}
|
||||
},
|
||||
"hirasetting": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user