Scriptorium / tests /test_voice_presets.py
mattkevan's picture
add modal endpoint and magpietts
cd0ff97
Raw
History Blame Contribute Delete
2.68 kB
import asyncio
import importlib
import sys
from omnivoice.utils.voice_design import _INSTRUCT_VALID_EN
from backend.voice_design import VOICE_DESIGN_OPTIONS
from backend.voice_presets import VOICE_PRESETS
def test_voice_presets_match_their_scriptorium_descriptions() -> None:
assert VOICE_PRESETS == [
{
"id": "the-archivist",
"name": "The Archivist",
"desc": "Voice design preset 路 elderly monk 路 low pitch 路 british accent",
"initial": "A",
"instruct": "male, elderly, low pitch, british accent",
},
{
"id": "the-novice",
"name": "The Novice",
"desc": "Voice design preset 路 young sister 路 moderate pitch 路 british accent",
"initial": "N",
"instruct": "female, young adult, moderate pitch, british accent",
},
{
"id": "the-warden",
"name": "The Warden",
"desc": "Voice design preset 路 stern keeper 路 very low pitch 路 american accent",
"initial": "W",
"instruct": "male, middle-aged, very low pitch, american accent",
},
{
"id": "the-illuminator",
"name": "The Illuminator",
"desc": "Voice design preset 路 bright scholar 路 high pitch 路 canadian accent",
"initial": "I",
"instruct": "female, middle-aged, high pitch, canadian accent",
},
]
def test_voice_presets_use_only_supported_omnivoice_design_tokens() -> None:
for preset in VOICE_PRESETS:
instruct = preset["instruct"]
parts = [part.strip().lower() for part in instruct.split(",")]
assert all(parts), f"Preset {preset['id']} contains an empty instruct token"
assert all(
part in _INSTRUCT_VALID_EN for part in parts
), f"Preset {preset['id']} has unsupported instruct tokens: {instruct}"
def test_homepage_injects_voice_presets_for_frontend() -> None:
sys.modules.pop("app", None)
module = importlib.import_module("app")
response = asyncio.run(module.homepage())
html = response.body.decode("utf-8")
assert "window.__VOICE_PRESETS__" in html
assert "window.__VOICE_DESIGN_OPTIONS__" in html
assert "window.__MAGPIE_OPTIONS__" in html
assert "window.__SYNTHESIS_BACKENDS__" in html
def test_voice_design_options_use_only_supported_omnivoice_design_tokens() -> None:
option_values = [
option["value"]
for category in VOICE_DESIGN_OPTIONS
for option in category["options"]
]
assert option_values
assert all(value in _INSTRUCT_VALID_EN for value in option_values)