projects include proper noun stuff

This commit is contained in:
2026-04-08 01:52:54 -06:00
parent 894144c84a
commit e9ddbb586a
2 changed files with 44 additions and 9 deletions

View File

@ -68,6 +68,8 @@ from PySide6.QtGui import *
class Project(NamedTuple): class Project(NamedTuple):
name: str name: str
source_paths: list[Path] source_paths: list[Path]
proper_nouns_output_dir: Path
proper_nouns_audio_dir: Path
def _project_slug(name: str) -> str: def _project_slug(name: str) -> str:
return re.sub(r"[^a-zA-Z0-9_-]", "_", name).strip("_")[:60].lower() return re.sub(r"[^a-zA-Z0-9_-]", "_", name).strip("_")[:60].lower()
@ -79,12 +81,29 @@ def load_projects() -> list[Project]:
projects = [] projects = []
for item in data: for item in data:
paths = [Path(p) for p in item["source_paths"]] paths = [Path(p) for p in item["source_paths"]]
projects.append(Project(name=item["name"], source_paths=paths)) output_dir = Path(item["proper_nouns_output_dir"])
audio_dir = Path(item["proper_nouns_audio_dir"])
projects.append(
Project(
name=item["name"],
source_paths=paths,
proper_nouns_output_dir=output_dir,
proper_nouns_audio_dir=audio_dir,
)
)
return projects return projects
return [] return []
def save_projects(projects: list[Project]) -> None: def save_projects(projects: list[Project]) -> None:
data = [{"name": p.name, "source_paths": [str(path) for path in p.source_paths]} for p in projects] data = [
{
"name": p.name,
"source_paths": [str(path) for path in p.source_paths],
"proper_nouns_output_dir": str(p.proper_nouns_output_dir),
"proper_nouns_audio_dir": str(p.proper_nouns_audio_dir),
}
for p in projects
]
Path("projects.json").write_text(json.dumps(data, indent=2), encoding="utf-8") Path("projects.json").write_text(json.dumps(data, indent=2), encoding="utf-8")
VOICE = "am_michael" VOICE = "am_michael"
@ -97,6 +116,8 @@ class BookSource(NamedTuple):
slug: str # Filesystem-safe identifier used for subdirectory names slug: str # Filesystem-safe identifier used for subdirectory names
source_paths: list # list[Path] — one or more source .txt files source_paths: list # list[Path] — one or more source .txt files
fixed_out: Path # Where "Apply Fixes to Text" writes the TTS-ready copy fixed_out: Path # Where "Apply Fixes to Text" writes the TTS-ready copy
proper_nouns_output_dir: Path
proper_nouns_audio_dir: Path
def _book_slug(text: str) -> str: def _book_slug(text: str) -> str:
@ -111,7 +132,9 @@ def load_books_from_projects() -> list[BookSource]:
slug = _project_slug(project.name) slug = _project_slug(project.name)
fixed_out = Path(f"{project.name} (TTS Fixed).txt") fixed_out = Path(f"{project.name} (TTS Fixed).txt")
books.append(BookSource(label=project.name, slug=slug, books.append(BookSource(label=project.name, slug=slug,
source_paths=project.source_paths, fixed_out=fixed_out)) source_paths=project.source_paths, fixed_out=fixed_out,
proper_nouns_output_dir=project.proper_nouns_output_dir,
proper_nouns_audio_dir=project.proper_nouns_audio_dir))
return books return books
# ── Colours ──────────────────────────────────────────────────────────────────── # ── Colours ────────────────────────────────────────────────────────────────────
@ -368,11 +391,11 @@ class ProperNounAuditor(QMainWindow):
@property @property
def _data_dir(self) -> Path: def _data_dir(self) -> Path:
return Path("output_proper_nouns") / self.book.slug return self.book.proper_nouns_output_dir
@property @property
def _audio_dir(self) -> Path: def _audio_dir(self) -> Path:
return Path("proper_nouns_audio") / self.book.slug return self.book.proper_nouns_audio_dir
@property @property
def _manifest_file(self) -> Path: def _manifest_file(self) -> Path:
@ -434,7 +457,9 @@ class ProperNounAuditor(QMainWindow):
slug = _project_slug(project.name) slug = _project_slug(project.name)
fixed_out = Path(f"{project.name} (TTS Fixed).txt") fixed_out = Path(f"{project.name} (TTS Fixed).txt")
book = BookSource(label=project.name, slug=slug, book = BookSource(label=project.name, slug=slug,
source_paths=project.source_paths, fixed_out=fixed_out) source_paths=project.source_paths, fixed_out=fixed_out,
proper_nouns_output_dir=project.proper_nouns_output_dir,
proper_nouns_audio_dir=project.proper_nouns_audio_dir)
self.books = [book] self.books = [book]
self._load_book(book) self._load_book(book)
@ -449,7 +474,13 @@ class ProperNounAuditor(QMainWindow):
files, _ = QFileDialog.getOpenFileNames(self, "Select TXT files", "", "Text files (*.txt)") files, _ = QFileDialog.getOpenFileNames(self, "Select TXT files", "", "Text files (*.txt)")
if files: if files:
paths = [Path(f) for f in files] paths = [Path(f) for f in files]
project = Project(name=name, source_paths=paths) slug = _project_slug(name)
project = Project(
name=name,
source_paths=paths,
proper_nouns_output_dir=Path("output_proper_nouns") / slug,
proper_nouns_audio_dir=Path("proper_nouns_audio") / slug,
)
self.projects.append(project) self.projects.append(project)
save_projects(self.projects) save_projects(self.projects)
# Update combobox values # Update combobox values

View File

@ -3,12 +3,16 @@
"name": "Audio Text for Novel Lightbringer", "name": "Audio Text for Novel Lightbringer",
"source_paths": [ "source_paths": [
"/home/dillon/_code/voice_model/Audio Text for Novel Lightbringer/Audio Text for Novel Lightbringer.txt" "/home/dillon/_code/voice_model/Audio Text for Novel Lightbringer/Audio Text for Novel Lightbringer.txt"
] ],
"proper_nouns_output_dir": "output_proper_nouns/audio_text_for_novel_lightbringer",
"proper_nouns_audio_dir": "proper_nouns_audio/audio_text_for_novel_lightbringer"
}, },
{ {
"name": "visions glory canada", "name": "visions glory canada",
"source_paths": [ "source_paths": [
"/home/dillon/_code/voice_model/Visions of Glory_ Zion in Canada pg 162-193.txt" "/home/dillon/_code/voice_model/Visions of Glory_ Zion in Canada pg 162-193.txt"
] ],
"proper_nouns_output_dir": "output_proper_nouns/visions_glory_canada",
"proper_nouns_audio_dir": "proper_nouns_audio/visions_glory_canada"
} }
] ]