From 47f679215937af051948556fa28e19d0213aa163 Mon Sep 17 00:00:00 2001 From: Logi E Date: Wed, 30 Aug 2023 15:12:58 +0000 Subject: [PATCH] Fix circular import --- src/icespeak/__init__.py | 6 ++++-- src/icespeak/parser.py | 20 +++++++++++++++++++- src/icespeak/transcribe/__init__.py | 16 ---------------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/icespeak/__init__.py b/src/icespeak/__init__.py index 736957f..a795593 100644 --- a/src/icespeak/__init__.py +++ b/src/icespeak/__init__.py @@ -19,8 +19,9 @@ """ -from .parser import GreynirSSMLParser -from .transcribe import DefaultTranscriber, TranscriptionOptions, fast_transcribe, gssml +from .parser import GreynirSSMLParser, fast_transcribe +from .settings import SETTINGS +from .transcribe import DefaultTranscriber, TranscriptionOptions, gssml from .tts import AVAILABLE_VOICES, text_to_speech __all__ = ( @@ -31,4 +32,5 @@ "AVAILABLE_VOICES", "TranscriptionOptions", "fast_transcribe", + "SETTINGS", ) diff --git a/src/icespeak/parser.py b/src/icespeak/parser.py index 5d5ba9f..7162dc7 100644 --- a/src/icespeak/parser.py +++ b/src/icespeak/parser.py @@ -28,12 +28,30 @@ from logging import getLogger from .settings import SETTINGS -from .transcribe import GSSML_TAG, DefaultTranscriber, TranscriptionMethod +from .transcribe import ( + GSSML_TAG, + DefaultTranscriber, + TranscriptionMethod, + TranscriptionOptions, +) from .tts import AVAILABLE_VOICES _LOG = getLogger(__file__) +def fast_transcribe( + text: str, + voice: str = SETTINGS.DEFAULT_VOICE, + options: TranscriptionOptions | None = None, +): + """ + Simple wrapper for token-based transcription + of text for a specific TTS voice. + """ + t = AVAILABLE_VOICES[voice]["Transcriber"] or DefaultTranscriber + return t.token_transcribe(text, options) + + class GreynirSSMLParser(HTMLParser): """ Parses voice strings containing tags and diff --git a/src/icespeak/transcribe/__init__.py b/src/icespeak/transcribe/__init__.py index 0809fb1..90f4561 100644 --- a/src/icespeak/transcribe/__init__.py +++ b/src/icespeak/transcribe/__init__.py @@ -45,9 +45,6 @@ PunctuationTuple, ) -from icespeak.settings import SETTINGS -from icespeak.tts import AVAILABLE_VOICES - from .num import ( ROMAN_NUMERALS, CaseType, @@ -1512,16 +1509,3 @@ def token_transcribe( token.txt = cls.entity(token.txt) return detokenize(tokens) - - -def fast_transcribe( - text: str, - voice: str = SETTINGS.DEFAULT_VOICE, - options: TranscriptionOptions | None = None, -): - """ - Simple wrapper for token-based transcription - of text for a specific TTS voice. - """ - t = AVAILABLE_VOICES[voice]["Transcriber"] or DefaultTranscriber - return t.token_transcribe(text, options)