-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
354bc1c
commit 8ce510b
Showing
15 changed files
with
703 additions
and
394 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
VERSION = "v3.47" | ||
VERSION_NUM = 120347 | ||
VERSION = "v3.48" | ||
VERSION_NUM = 120348 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import copy | ||
import re | ||
import time | ||
from pathlib import Path | ||
|
||
import requests | ||
from pydub import AudioSegment | ||
|
||
from videotrans.configure import config | ||
from videotrans.tts._base import BaseTTS | ||
from videotrans.util import tools | ||
|
||
|
||
# 线程池并发 返回wav数据,转为mp3 | ||
|
||
class KokoroTTS(BaseTTS): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
api_url = config.params['kokoro_api'].strip().rstrip('/').lower() | ||
self.api_url = 'http://' + api_url.replace('http://', '') | ||
if not self.api_url.endswith('/v1/audio/speech'): | ||
self.api_url+='/v1/audio/speech' | ||
self.proxies={"http": "", "https": ""} | ||
|
||
def _exec(self): | ||
self._local_mul_thread() | ||
|
||
def _item_task(self, data_item: dict = None): | ||
if self._exit(): | ||
return | ||
if not data_item: | ||
return | ||
try: | ||
text = data_item['text'].strip() | ||
speed = 1.0 | ||
if self.rate: | ||
rate = float(self.rate.replace('%', '')) / 100 | ||
speed += rate | ||
data = {"input": text, "voice": data_item['role'],"speed":speed} | ||
|
||
res = requests.post(self.api_url, json=data, proxies=self.proxies, timeout=3600) | ||
res.raise_for_status() | ||
|
||
with open(data_item['filename'], 'wb') as f: | ||
f.write(res.content) | ||
if self.inst and self.inst.precent < 80: | ||
self.inst.precent += 0.1 | ||
self.error = '' | ||
self.has_done += 1 | ||
except (requests.ConnectionError, requests.Timeout) as e: | ||
self.error="连接失败,请检查是否启动了api服务" if config.defaulelang=='zh' else 'Connection failed, please check if the api service is started' | ||
except Exception as e: | ||
Path(data_item['filename']).unlink(missing_ok=True) | ||
self.error = str(e) | ||
config.logger.exception(e, exc_info=True) | ||
finally: | ||
if self.error: | ||
self._signal(text=self.error) | ||
else: | ||
self._signal(text=f'{config.transobj["kaishipeiyin"]} {self.has_done}/{self.len}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# run again. Do not edit this file unless you know what you are doing. | ||
|
||
|
||
from PySide6 import QtCore, QtWidgets | ||
from PySide6.QtCore import Qt | ||
from PySide6.QtWidgets import QLabel | ||
|
||
from videotrans.configure import config | ||
from videotrans.util import tools | ||
|
||
|
||
class Ui_kokoroform(object): | ||
def setupUi(self, kokoro): | ||
self.has_done = False | ||
kokoro.setObjectName("kokoro") | ||
kokoro.setWindowModality(QtCore.Qt.NonModal) | ||
kokoro.resize(500, 223) | ||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) | ||
sizePolicy.setHorizontalStretch(0) | ||
sizePolicy.setVerticalStretch(0) | ||
sizePolicy.setHeightForWidth(kokoro.sizePolicy().hasHeightForWidth()) | ||
kokoro.setSizePolicy(sizePolicy) | ||
kokoro.setMaximumSize(QtCore.QSize(500, 300)) | ||
|
||
|
||
self.verticalLayout = QtWidgets.QVBoxLayout(kokoro) | ||
self.verticalLayout.setObjectName("verticalLayout") | ||
self.formLayout_2 = QtWidgets.QFormLayout() | ||
self.formLayout_2.setSizeConstraint(QtWidgets.QLayout.SetMinimumSize) | ||
self.formLayout_2.setFormAlignment(QtCore.Qt.AlignJustify | QtCore.Qt.AlignVCenter) | ||
self.formLayout_2.setObjectName("formLayout_2") | ||
self.label = QtWidgets.QLabel(kokoro) | ||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) | ||
sizePolicy.setHorizontalStretch(0) | ||
sizePolicy.setVerticalStretch(0) | ||
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth()) | ||
self.label.setSizePolicy(sizePolicy) | ||
self.label.setMinimumSize(QtCore.QSize(100, 35)) | ||
self.label.setAlignment(QtCore.Qt.AlignJustify | QtCore.Qt.AlignVCenter) | ||
self.label.setObjectName("label") | ||
|
||
self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label) | ||
self.kokoro_address = QtWidgets.QLineEdit(kokoro) | ||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) | ||
sizePolicy.setHorizontalStretch(0) | ||
sizePolicy.setVerticalStretch(0) | ||
sizePolicy.setHeightForWidth(self.kokoro_address.sizePolicy().hasHeightForWidth()) | ||
self.kokoro_address.setSizePolicy(sizePolicy) | ||
self.kokoro_address.setMinimumSize(QtCore.QSize(400, 35)) | ||
self.kokoro_address.setObjectName("kokoro_address") | ||
|
||
self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.kokoro_address) | ||
self.verticalLayout.addLayout(self.formLayout_2) | ||
|
||
|
||
self.set_kokoro = QtWidgets.QPushButton(kokoro) | ||
self.set_kokoro.setMinimumSize(QtCore.QSize(0, 35)) | ||
self.set_kokoro.setObjectName("set_kokoro") | ||
|
||
self.test = QtWidgets.QPushButton(kokoro) | ||
self.test.setMinimumSize(QtCore.QSize(0, 30)) | ||
self.test.setObjectName("test") | ||
help_btn = QtWidgets.QPushButton() | ||
help_btn.setMinimumSize(QtCore.QSize(0, 35)) | ||
help_btn.setStyleSheet("background-color: rgba(255, 255, 255,0)") | ||
help_btn.setObjectName("help_btn") | ||
help_btn.setCursor(Qt.PointingHandCursor) | ||
help_btn.setText("查看填写教程" if config.defaulelang == 'zh' else "Fill out the tutorial") | ||
help_btn.clicked.connect(lambda: tools.open_url(url='https://pyvideotrans.com/kokorotts')) | ||
|
||
self.layout_btn = QtWidgets.QHBoxLayout() | ||
self.layout_btn.setObjectName("layout_btn") | ||
|
||
self.layout_btn.addWidget(self.set_kokoro) | ||
self.layout_btn.addWidget(self.test) | ||
self.layout_btn.addWidget(help_btn) | ||
|
||
self.verticalLayout.addLayout(self.layout_btn) | ||
|
||
|
||
|
||
self.retranslateUi(kokoro) | ||
QtCore.QMetaObject.connectSlotsByName(kokoro) | ||
|
||
def retranslateUi(self, kokoro): | ||
kokoro.setWindowTitle("Kokoro TTS") | ||
self.label.setText("http地址" if config.defaulelang == 'zh' else 'kokoro api') | ||
self.kokoro_address.setPlaceholderText( | ||
'kokoro-uiapi启动后的地址,默认请填写 http://127.0.0.1:5066' if config.defaulelang == 'zh' else 'Fill in the HTTP address after the kokoro program starts') | ||
self.set_kokoro.setText('保存' if config.defaulelang == 'zh' else "Save") | ||
self.test.setText('测试' if config.defaulelang == 'zh' else "Test") |
Oops, something went wrong.