caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

104 lines
3.5 KiB
Python

"""Named voice emotion/delivery presets for ElevenLabs TTS.
Competitor parity (2026): Arcads lets a caller steer an AI actor's delivery with
a text prompt ("excited", "persuasive", "concerned") and InVideo's voice
cloning now carries "subtle emotional inflections" — both ship emotion control
as a first-class ad-generation input. Menivor's ElevenLabs call sites
(``app.services.voice.elevenlabs_tts``,
``app.services.tts.elevenlabs_timestamps.elevenlabs_tts_with_timestamps`` and
the media-gateway's ``ElevenLabsVoiceAdapter``) previously hardcoded
``voice_settings`` to one flat, neutral delivery. This module is the single
source of truth those three call sites now share.
ElevenLabs' own emotion knobs are ``stability`` (lower = more variable /
expressive delivery) and ``style`` (0.0-1.0 exaggeration of the voice's
inherent style) — see
https://elevenlabs.io/docs/api-reference/text-to-speech#voice-settings and
https://elevenlabs.io/docs/best-practices/prompting. ``neutral`` reproduces the
exact values every call site hardcoded before this module existed, so passing
no emotion (or an unknown one) is a no-op: existing callers keep their current
audio byte-for-byte.
"""
from __future__ import annotations
DEFAULT_EMOTION: str = "neutral"
#: name -> ElevenLabs ``voice_settings``. Every entry is a complete, independent
#: dict (never shared/mutated) so callers can safely treat the return value of
#: :func:`resolve_voice_settings` as owned.
_VOICE_SETTINGS: dict[str, dict[str, float | bool]] = {
# The exact values every ElevenLabs call site hardcoded previously.
"neutral": {
"stability": 0.5,
"similarity_boost": 0.75,
"style": 0.0,
"use_speaker_boost": True,
},
"excited": {
"stability": 0.3,
"similarity_boost": 0.75,
"style": 0.6,
"use_speaker_boost": True,
},
"calm": {
"stability": 0.7,
"similarity_boost": 0.75,
"style": 0.1,
"use_speaker_boost": True,
},
"urgent": {
"stability": 0.25,
"similarity_boost": 0.8,
"style": 0.7,
"use_speaker_boost": True,
},
"persuasive": {
"stability": 0.4,
"similarity_boost": 0.8,
"style": 0.5,
"use_speaker_boost": True,
},
"warm": {
"stability": 0.55,
"similarity_boost": 0.75,
"style": 0.35,
"use_speaker_boost": True,
},
"dramatic": {
"stability": 0.2,
"similarity_boost": 0.8,
"style": 0.8,
"use_speaker_boost": True,
},
}
#: Stable, user-facing catalog order (e.g. for a frontend dropdown).
EMOTIONS: tuple[str, ...] = tuple(_VOICE_SETTINGS.keys())
def normalize_emotion(value: str | None) -> str:
"""A known emotion name, lower-cased and stripped; ``DEFAULT_EMOTION`` for
anything empty or unrecognized. Never raises — mirrors the rest of the TTS
stack's best-effort contract (a bad/unknown value degrades to neutral
delivery rather than failing the whole generation)."""
key = str(value or "").strip().lower()
return key if key in _VOICE_SETTINGS else DEFAULT_EMOTION
def resolve_voice_settings(emotion: str | None) -> dict[str, float | bool]:
"""The ElevenLabs ``voice_settings`` payload for ``emotion``.
Always returns a fresh dict (never a shared reference) so a caller is free
to mutate its copy without affecting the catalog or any other caller.
"""
return dict(_VOICE_SETTINGS[normalize_emotion(emotion)])
__all__ = [
"DEFAULT_EMOTION",
"EMOTIONS",
"normalize_emotion",
"resolve_voice_settings",
]