mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
issues/752
This commit is contained in:
parent
fe5b4dbef7
commit
45d95fc695
@ -11,9 +11,6 @@ import time
|
|||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QApplication,
|
QApplication,
|
||||||
)
|
)
|
||||||
from PyQt5.QtCore import QIODevice, QBuffer
|
|
||||||
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
|
|
||||||
|
|
||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
from myutils.config import (
|
from myutils.config import (
|
||||||
globalconfig,
|
globalconfig,
|
||||||
@ -238,38 +235,77 @@ def argsort(l):
|
|||||||
|
|
||||||
|
|
||||||
class wavmp3player:
|
class wavmp3player:
|
||||||
def changepos(self, pos):
|
|
||||||
if pos != 0 and pos == self.player.duration():
|
|
||||||
if self.next:
|
|
||||||
content, volume = self.next
|
|
||||||
self.next = None
|
|
||||||
self.realplay(content, volume)
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.player = QMediaPlayer()
|
self.i = 0
|
||||||
self.player.positionChanged.connect(self.changepos)
|
self.lastfile = None
|
||||||
self.next = None
|
self.tasks = None
|
||||||
|
self.lock = threading.Lock()
|
||||||
|
self.lock.acquire()
|
||||||
|
threading.Thread(target=self.dotasks).start()
|
||||||
|
|
||||||
def realplay(self, content, volume):
|
def mp3playfunction(self, binary, volume, force):
|
||||||
self.player.stop()
|
try:
|
||||||
self.keepbuffer = []
|
self.tasks = (binary, volume, force)
|
||||||
buffer = QBuffer()
|
self.lock.release()
|
||||||
buffer.open(QIODevice.ReadWrite)
|
except:
|
||||||
self.player.setMedia(QMediaContent(), buffer)
|
pass
|
||||||
self.player.setVolume(volume)
|
|
||||||
buffer.write(content)
|
|
||||||
self.keepbuffer = [buffer]
|
|
||||||
self.player.play()
|
|
||||||
|
|
||||||
def mp3playfunction(self, content, volume, force):
|
def dotasks(self):
|
||||||
if (
|
durationms = 0
|
||||||
globalconfig["ttsnointerrupt"]
|
try:
|
||||||
and self.player.position() < self.player.duration()
|
while True:
|
||||||
and not force
|
self.lock.acquire()
|
||||||
):
|
task = self.tasks
|
||||||
self.next = [content, volume]
|
self.tasks = None
|
||||||
else:
|
if task is None:
|
||||||
self.realplay(content, volume)
|
continue
|
||||||
|
binary, volume, force = task
|
||||||
|
os.makedirs("./cache/tts", exist_ok=True)
|
||||||
|
|
||||||
|
tgt = os.path.abspath("./cache/tts/" + str(time.time()) + ".wav")
|
||||||
|
with open(tgt, "wb") as ff:
|
||||||
|
ff.write(binary)
|
||||||
|
durationms = self._playsoundWin(tgt, volume)
|
||||||
|
self.lastfile = tgt
|
||||||
|
if durationms and globalconfig["ttsnointerrupt"]:
|
||||||
|
while durationms > 0:
|
||||||
|
durationms -= 100
|
||||||
|
time.sleep(0.1)
|
||||||
|
if self.tasks and self.tasks[-1]:
|
||||||
|
break
|
||||||
|
# time.sleep(durationms / 1000)
|
||||||
|
except:
|
||||||
|
print_exc()
|
||||||
|
|
||||||
|
def _playsoundWin(self, sound, volume):
|
||||||
|
try:
|
||||||
|
|
||||||
|
windows.mciSendString(("stop lunatranslator_mci_{}".format(self.i)))
|
||||||
|
windows.mciSendString(("close lunatranslator_mci_{}".format(self.i)))
|
||||||
|
self.i += 1
|
||||||
|
if self.lastfile:
|
||||||
|
os.remove(self.lastfile)
|
||||||
|
self.lastfile = sound
|
||||||
|
windows.mciSendString(
|
||||||
|
'open "{}" type mpegvideo alias lunatranslator_mci_{}'.format(
|
||||||
|
sound, self.i
|
||||||
|
)
|
||||||
|
)
|
||||||
|
durationms = int(
|
||||||
|
windows.mciSendString(
|
||||||
|
"status lunatranslator_mci_{} length".format(self.i)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
windows.mciSendString(
|
||||||
|
"setaudio lunatranslator_mci_{} volume to {}".format(
|
||||||
|
self.i, volume * 10
|
||||||
|
)
|
||||||
|
)
|
||||||
|
windows.mciSendString(("play lunatranslator_mci_{}".format(self.i)))
|
||||||
|
except:
|
||||||
|
durationms = 0
|
||||||
|
|
||||||
|
return durationms
|
||||||
|
|
||||||
|
|
||||||
def selectdebugfile(path):
|
def selectdebugfile(path):
|
||||||
|
@ -183,20 +183,6 @@ copycheck(
|
|||||||
os.path.join(runtime, "PyQt5/Qt5/bin"),
|
os.path.join(runtime, "PyQt5/Qt5/bin"),
|
||||||
)
|
)
|
||||||
|
|
||||||
###
|
|
||||||
copycheck(
|
|
||||||
os.path.join(py37Path, "Lib/site-packages/PyQt5/Qt5/bin/Qt5Multimedia.dll"),
|
|
||||||
os.path.join(runtime, "PyQt5/Qt5/bin"),
|
|
||||||
)
|
|
||||||
copycheck(
|
|
||||||
os.path.join(py37Path, "Lib/site-packages/PyQt5/Qt5/bin/Qt5Network.dll"),
|
|
||||||
os.path.join(runtime, "PyQt5/Qt5/bin"),
|
|
||||||
)
|
|
||||||
copycheck(
|
|
||||||
os.path.join(py37Path, "Lib/site-packages/PyQt5/QtNetwork.pyd"),
|
|
||||||
os.path.join(runtime, "PyQt5"),
|
|
||||||
)
|
|
||||||
###
|
|
||||||
copycheck(
|
copycheck(
|
||||||
os.path.join(py37Path, "Lib/site-packages/PyQt5/Qt5/bin/Qt5Widgets.dll"),
|
os.path.join(py37Path, "Lib/site-packages/PyQt5/Qt5/bin/Qt5Widgets.dll"),
|
||||||
os.path.join(runtime, "PyQt5/Qt5/bin"),
|
os.path.join(runtime, "PyQt5/Qt5/bin"),
|
||||||
@ -206,10 +192,6 @@ copycheck(
|
|||||||
os.path.join(py37Path, "Lib/site-packages/PyQt5/Qt5/plugins/imageformats"),
|
os.path.join(py37Path, "Lib/site-packages/PyQt5/Qt5/plugins/imageformats"),
|
||||||
os.path.join(runtime, "PyQt5/Qt5/plugins"),
|
os.path.join(runtime, "PyQt5/Qt5/plugins"),
|
||||||
)
|
)
|
||||||
copycheck(
|
|
||||||
os.path.join(py37Path, "Lib/site-packages/PyQt5/Qt5/plugins/mediaservice"),
|
|
||||||
os.path.join(runtime, "PyQt5/Qt5/plugins"),
|
|
||||||
)
|
|
||||||
copycheck(
|
copycheck(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
py37Path, "Lib/site-packages/PyQt5/Qt5/plugins/platforms/qoffscreen.dll"
|
py37Path, "Lib/site-packages/PyQt5/Qt5/plugins/platforms/qoffscreen.dll"
|
||||||
|
@ -29,7 +29,7 @@ include(generate_product_version)
|
|||||||
|
|
||||||
set(VERSION_MAJOR 2)
|
set(VERSION_MAJOR 2)
|
||||||
set(VERSION_MINOR 51)
|
set(VERSION_MINOR 51)
|
||||||
set(VERSION_PATCH 6)
|
set(VERSION_PATCH 7)
|
||||||
|
|
||||||
add_library(pch pch.cpp)
|
add_library(pch pch.cpp)
|
||||||
target_precompile_headers(pch PUBLIC pch.h)
|
target_precompile_headers(pch PUBLIC pch.h)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user