mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
tts2 -> tts
This commit is contained in:
parent
3146ffafca
commit
56be893064
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
from qt.core import QCheckBox, QFormLayout, QLabel, QLocale, QMediaDevices, QSize, QSlider, Qt, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal
|
from qt.core import QCheckBox, QFormLayout, QLabel, QLocale, QMediaDevices, QSize, QSlider, Qt, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal
|
||||||
|
|
||||||
from calibre.gui2.tts2.types import (
|
from calibre.gui2.tts.types import (
|
||||||
AudioDeviceId,
|
AudioDeviceId,
|
||||||
EngineMetadata,
|
EngineMetadata,
|
||||||
EngineSpecificSettings,
|
EngineSpecificSettings,
|
@ -8,7 +8,7 @@ from qt.core import QAction, QKeySequence, QPlainTextEdit, QSize, Qt, QTextCurso
|
|||||||
|
|
||||||
from calibre.gui2 import Application
|
from calibre.gui2 import Application
|
||||||
from calibre.gui2.main_window import MainWindow
|
from calibre.gui2.main_window import MainWindow
|
||||||
from calibre.gui2.tts2.manager import TTSManager
|
from calibre.gui2.tts.manager import TTSManager
|
||||||
|
|
||||||
TEXT = '''\
|
TEXT = '''\
|
||||||
Demonstration 🐈 of DOCX support in calibre
|
Demonstration 🐈 of DOCX support in calibre
|
@ -12,7 +12,7 @@ from calibre.gui2 import error_dialog
|
|||||||
from calibre.gui2.widgets import BusyCursor
|
from calibre.gui2.widgets import BusyCursor
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from calibre.gui2.tts2.types import TTSBackend
|
from calibre.gui2.tts.types import TTSBackend
|
||||||
|
|
||||||
|
|
||||||
class Utterance(NamedTuple):
|
class Utterance(NamedTuple):
|
||||||
@ -135,7 +135,7 @@ class TTSManager(QObject):
|
|||||||
def tts(self) -> 'TTSBackend':
|
def tts(self) -> 'TTSBackend':
|
||||||
if self._tts is None:
|
if self._tts is None:
|
||||||
with BusyCursor():
|
with BusyCursor():
|
||||||
from calibre.gui2.tts2.types import create_tts_backend
|
from calibre.gui2.tts.types import create_tts_backend
|
||||||
try:
|
try:
|
||||||
self._tts = create_tts_backend()
|
self._tts = create_tts_backend()
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
@ -182,7 +182,7 @@ class TTSManager(QObject):
|
|||||||
self.tts.resume()
|
self.tts.resume()
|
||||||
|
|
||||||
def change_rate(self, steps: int = 1) -> bool:
|
def change_rate(self, steps: int = 1) -> bool:
|
||||||
from calibre.gui2.tts2.types import EngineSpecificSettings
|
from calibre.gui2.tts.types import EngineSpecificSettings
|
||||||
engine_name = self.tts.engine_name
|
engine_name = self.tts.engine_name
|
||||||
s = EngineSpecificSettings.create_from_config(engine_name)
|
s = EngineSpecificSettings.create_from_config(engine_name)
|
||||||
new_rate = max(-1, min(s.rate + 0.2 * steps, 1))
|
new_rate = max(-1, min(s.rate + 0.2 * steps, 1))
|
||||||
@ -211,8 +211,8 @@ class TTSManager(QObject):
|
|||||||
QApplication.instance().beep()
|
QApplication.instance().beep()
|
||||||
|
|
||||||
def configure(self) -> None:
|
def configure(self) -> None:
|
||||||
from calibre.gui2.tts2.config import ConfigDialog
|
from calibre.gui2.tts.config import ConfigDialog
|
||||||
from calibre.gui2.tts2.types import widget_parent
|
from calibre.gui2.tts.types import widget_parent
|
||||||
with self.resume_after() as rd:
|
with self.resume_after() as rd:
|
||||||
d = ConfigDialog(parent=widget_parent(self))
|
d = ConfigDialog(parent=widget_parent(self))
|
||||||
if d.exec() == QDialog.DialogCode.Accepted and self._tts is not None:
|
if d.exec() == QDialog.DialogCode.Accepted and self._tts is not None:
|
@ -31,7 +31,7 @@ from qt.core import (
|
|||||||
|
|
||||||
from calibre.constants import cache_dir, is_debugging
|
from calibre.constants import cache_dir, is_debugging
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
from calibre.gui2.tts2.types import EngineSpecificSettings, Quality, TTSBackend, Voice, piper_cmdline, widget_parent
|
from calibre.gui2.tts.types import EngineSpecificSettings, Quality, TTSBackend, Voice, piper_cmdline, widget_parent
|
||||||
from calibre.spell.break_iterator import PARAGRAPH_SEPARATOR, split_into_sentences_for_tts
|
from calibre.spell.break_iterator import PARAGRAPH_SEPARATOR, split_into_sentences_for_tts
|
||||||
from calibre.utils.localization import canonicalize_lang, get_lang
|
from calibre.utils.localization import canonicalize_lang, get_lang
|
||||||
from calibre.utils.resources import get_path as P
|
from calibre.utils.resources import get_path as P
|
||||||
@ -442,7 +442,7 @@ class Piper(TTSBackend):
|
|||||||
if os.path.exists(model_path) and os.path.exists(config_path):
|
if os.path.exists(model_path) and os.path.exists(config_path):
|
||||||
return model_path, config_path
|
return model_path, config_path
|
||||||
os.makedirs(os.path.dirname(model_path), exist_ok=True)
|
os.makedirs(os.path.dirname(model_path), exist_ok=True)
|
||||||
from calibre.gui2.tts2.download import DownloadResources
|
from calibre.gui2.tts.download import DownloadResources
|
||||||
d = DownloadResources(_('Downloading voice for Read aloud'), _('Downloading neural network for the {} voice').format(voice.human_name), {
|
d = DownloadResources(_('Downloading voice for Read aloud'), _('Downloading neural network for the {} voice').format(voice.human_name), {
|
||||||
voice.engine_data['model_url']: (model_path, _('Neural network data')),
|
voice.engine_data['model_url']: (model_path, _('Neural network data')),
|
||||||
voice.engine_data['config_url']: (config_path, _('Neural network metadata')),
|
voice.engine_data['config_url']: (config_path, _('Neural network metadata')),
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
from qt.core import QMediaDevices, QObject, QTextToSpeech
|
from qt.core import QMediaDevices, QObject, QTextToSpeech
|
||||||
|
|
||||||
from calibre.gui2.tts2.types import EngineSpecificSettings, TTSBackend, Voice, qvoice_to_voice
|
from calibre.gui2.tts.types import EngineSpecificSettings, TTSBackend, Voice, qvoice_to_voice
|
||||||
|
|
||||||
|
|
||||||
class QtTTSBackend(TTSBackend):
|
class QtTTSBackend(TTSBackend):
|
@ -7,7 +7,7 @@ from qt.core import QObject, Qt, QTextToSpeech, pyqtSignal
|
|||||||
from speechd.client import CallbackType, DataMode, Priority, SpawnError, SSIPClient, SSIPCommunicationError
|
from speechd.client import CallbackType, DataMode, Priority, SpawnError, SSIPClient, SSIPCommunicationError
|
||||||
|
|
||||||
from calibre import prepare_string_for_xml
|
from calibre import prepare_string_for_xml
|
||||||
from calibre.gui2.tts2.types import EngineSpecificSettings, TTSBackend, Voice
|
from calibre.gui2.tts.types import EngineSpecificSettings, TTSBackend, Voice
|
||||||
from calibre.spell.break_iterator import split_into_words_and_positions
|
from calibre.spell.break_iterator import split_into_words_and_positions
|
||||||
from calibre.utils.localization import canonicalize_lang
|
from calibre.utils.localization import canonicalize_lang
|
||||||
|
|
@ -309,18 +309,18 @@ def create_tts_backend(force_engine: str | None = None) -> TTSBackend:
|
|||||||
engine_name = default_engine_name()
|
engine_name = default_engine_name()
|
||||||
if engine_name == 'piper':
|
if engine_name == 'piper':
|
||||||
if engine_name not in engine_instances:
|
if engine_name not in engine_instances:
|
||||||
from calibre.gui2.tts2.piper import Piper
|
from calibre.gui2.tts.piper import Piper
|
||||||
engine_instances[engine_name] = Piper(engine_name, QApplication.instance())
|
engine_instances[engine_name] = Piper(engine_name, QApplication.instance())
|
||||||
ans = engine_instances[engine_name]
|
ans = engine_instances[engine_name]
|
||||||
elif engine_name == 'speechd':
|
elif engine_name == 'speechd':
|
||||||
if engine_name not in engine_instances:
|
if engine_name not in engine_instances:
|
||||||
from calibre.gui2.tts2.speechd import SpeechdTTSBackend
|
from calibre.gui2.tts.speechd import SpeechdTTSBackend
|
||||||
engine_instances[engine_name] = SpeechdTTSBackend(engine_name, QApplication.instance())
|
engine_instances[engine_name] = SpeechdTTSBackend(engine_name, QApplication.instance())
|
||||||
ans = engine_instances[engine_name]
|
ans = engine_instances[engine_name]
|
||||||
else:
|
else:
|
||||||
if 'qt' not in engine_instances:
|
if 'qt' not in engine_instances:
|
||||||
# Bad things happen with more than one QTextToSpeech instance
|
# Bad things happen with more than one QTextToSpeech instance
|
||||||
from calibre.gui2.tts2.qt import QtTTSBackend
|
from calibre.gui2.tts.qt import QtTTSBackend
|
||||||
engine_instances['qt'] = QtTTSBackend(engine_name if engine_name in available_engines() else '', QApplication.instance())
|
engine_instances['qt'] = QtTTSBackend(engine_name if engine_name in available_engines() else '', QApplication.instance())
|
||||||
ans = engine_instances['qt']
|
ans = engine_instances['qt']
|
||||||
if ans.engine_name != engine_name:
|
if ans.engine_name != engine_name:
|
@ -21,7 +21,7 @@ class TTS(QObject):
|
|||||||
@property
|
@property
|
||||||
def manager(self):
|
def manager(self):
|
||||||
if self._manager is None:
|
if self._manager is None:
|
||||||
from calibre.gui2.tts2.manager import TTSManager
|
from calibre.gui2.tts.manager import TTSManager
|
||||||
self._manager = TTSManager(self)
|
self._manager = TTSManager(self)
|
||||||
self._manager.saying.connect(self.saying)
|
self._manager.saying.connect(self.saying)
|
||||||
self._manager.state_event.connect(self.state_event)
|
self._manager.state_event.connect(self.state_event)
|
||||||
|
@ -186,7 +186,7 @@ class TestImports(unittest.TestCase):
|
|||||||
exclude_modules.add('calibre.utils.open_with.osx')
|
exclude_modules.add('calibre.utils.open_with.osx')
|
||||||
if not islinux:
|
if not islinux:
|
||||||
exclude_modules |= {
|
exclude_modules |= {
|
||||||
'calibre.linux', 'calibre.gui2.tts2.speechd',
|
'calibre.linux', 'calibre.gui2.tts.speechd',
|
||||||
'calibre.utils.linux_trash', 'calibre.utils.open_with.linux',
|
'calibre.utils.linux_trash', 'calibre.utils.open_with.linux',
|
||||||
'calibre.gui2.linux_file_dialogs',
|
'calibre.gui2.linux_file_dialogs',
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user