Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(speech): wire the config-driven dropdowns, and correct verified rates
trohitg2e59a6fb3512
diff --git a/server/config/pricing.json b/server/config/pricing.jsonindex 7b5741da..58182d8b 100644--- a/server/config/pricing.json+++ b/server/config/pricing.json@@ -266,21 +266,21 @@"_default": 0.0000226},"elevenlabs": {- "_description": "Text-to-speech, billed per CHARACTER of input. ElevenLabs prices by subscription tier rather than by a flat published per-character rate, so this is the Creator-tier effective rate (~$0.30 per 1,000 characters) and is an ESTIMATE. Operators on another tier should edit this value — the node reports the character count truthfully either way.",- "_source": "https://elevenlabs.io/pricing",+ "_description": "Text-to-speech, billed per CHARACTER of input. VERIFIED against the published API rate card: $0.10 per 1,000 characters for Multilingual v2/v3 (eleven_multilingual_v2 is the default model here) and $0.05 per 1,000 for Flash/Turbo. This table has no per-model axis, so the higher multilingual rate is used — an install running mostly Flash should halve it. Plans include a character quota; overage is charged at these same rates, so this is the marginal cost rather than the average.",+ "_source": "https://elevenlabs.io/pricing/api","_updated": "2026-07",- "text_to_speech": 0.0003,- "_default": 0.0003+ "text_to_speech": 0.0001,+ "_default": 0.0001},"deepgram": {- "_description": "Speech-to-text, billed per MINUTE of audio. Pay-as-you-go rate for the nova-3 family. The node converts measured seconds to minutes before recording, so resource_count here is minutes, not seconds.",+ "_description": "Speech-to-text, billed per MINUTE of audio. VERIFIED Pay-As-You-Go rate for Nova-3 Monolingual pre-recorded ($0.0077/min); Nova-3 Multilingual is $0.0092/min. The node converts measured seconds to minutes before recording, so resource_count here is minutes, not seconds.","_source": "https://deepgram.com/pricing","_updated": "2026-07",- "speech_to_text": 0.0043,- "_default": 0.0043+ "speech_to_text": 0.0077,+ "_default": 0.0077},"openai": {- "_description": "OpenAI's /audio/* routes only. These are NOT token-priced, so they live here rather than under `llm.openai` — the two blocks are separate namespaces and do not collide. text_to_speech bills per CHARACTER of input ($0.60 per 1M characters for gpt-4o-mini-tts, the default model; tts-1 is ~25x that, and this table has no per-model axis, so a tts-1-heavy install should raise this value). speech_to_text bills per SECOND ($0.006/minute for whisper-1).",+ "_description": "OpenAI's /audio/* routes only. These live here rather than under `llm.openai` — the two blocks are separate namespaces and do not collide. speech_to_text bills per SECOND and is accurate: $0.006/minute (gpt-4o-transcribe and whisper-1) = $0.0001/sec; gpt-4o-mini-transcribe is half that. text_to_speech UNDER-REPORTS and cannot fully be fixed in this schema: gpt-4o-mini-tts charges $0.60 per 1M INPUT characters (the figure below) PLUS $12 per 1M audio OUTPUT tokens, which usually dominates — OpenAI's own all-in estimate is ~$0.015/minute of speech. This table bills per character with no output-token axis, so an operator who wants the total reflected should raise text_to_speech to roughly 0.0000167 (that estimate at ~900 characters/minute of speech).","_source": "https://openai.com/api/pricing/","_updated": "2026-07","text_to_speech": 0.0000006,diff --git a/server/config/speech_defaults.json b/server/config/speech_defaults.jsonindex a70ac8d9..df0cb6ad 100644--- a/server/config/speech_defaults.json+++ b/server/config/speech_defaults.json@@ -1,6 +1,12 @@{"_comment": "Per-provider speech capabilities. Sibling of llm_defaults.json and read the same way: services/speech/config.py loads this once at import and every capability lookup goes through it, so shared code never branches on a provider name. Values here were verified against live official docs; see docs-internal/speech_provider_rfc.md section 7 for the sources and for the handful of items the docs do not state. Per-model overrides use the same {'model-id': value, '_default': value} shape as llm_defaults.json's max_output_tokens.","version": "1.0",+ "_common_languages_comment": "Fallback for the Language dropdown when a provider does not declare a closed list of its own. OpenAI/Whisper, Deepgram and Groq accept far more codes than these; this is a convenience shortlist, and 'Auto-detect' (empty value) is always offered first. A provider WITH a closed set (Sarvam) declares `languages` in its own block and that wins.",+ "common_languages": [+ "en", "es", "fr", "de", "it", "pt", "nl", "pl", "ru", "uk", "tr",+ "ar", "he", "fa", "hi", "bn", "ta", "te", "ur", "id", "vi", "th",+ "zh", "ja", "ko"+ ],"providers": {"openai": {"base_url": "https://api.openai.com/v1",@@ -142,8 +148,10 @@},"_smart_format_comment": "smart_format supersedes punctuate and additionally applies paragraphing plus number/date/currency formatting.","default_smart_format": true,- "_max_upload_comment": "Deepgram publishes no cloud file-size or duration cap. The 25 MB figure in circulation belongs to their self-hosted SageMaker docs and does not apply here, so no limit is asserted; services.media's read cap is the only ceiling.",- "max_upload_bytes": null,+ "_max_upload_comment": "VERIFIED from the Limits section of the pre-recorded-audio docs: 2 GB maximum file size. That is far above services.media's own 25 MiB read cap, which is therefore the binding limit in practice — the value is recorded for accuracy, not because it will ever be hit here. (An earlier revision claimed no cap was published; that was wrong.)",+ "max_upload_bytes": 2147483648,+ "_max_duration_comment": "ALSO verified, and this one bites: a synchronous request over 10 minutes of audio (Nova/Base/Enhanced) or 20 minutes (Whisper) returns 504 Gateway Timeout rather than a transcript. Long recordings need Deepgram's callback flow, which this node does not implement.",+ "max_duration_seconds": 600,"billed_unit": "minutes"}},diff --git a/server/nodes/speech/__init__.py b/server/nodes/speech/__init__.pyindex 49d75353..1285508f 100644--- a/server/nodes/speech/__init__.py+++ b/server/nodes/speech/__init__.py@@ -35,7 +35,13 @@ from __future__ import annotationsfrom services.node_output_schemas import register_output_schemafrom services.ws_handler_registry import register_option_loader-from ._option_loaders import load_speech_models, load_speech_voices+from ._option_loaders import (+ load_speech_formats,+ load_speech_languages,+ load_speech_models,+ load_speech_sample_rates,+ load_speech_voices,+)from .speech_to_text import SpeechToTextNode, SpeechToTextOutputfrom .text_to_speech import TextToSpeechNode, TextToSpeechOutput@@ -48,6 +54,9 @@ register_output_schema(SpeechToTextNode.type, SpeechToTextOutput)# the Params fields or `test_node_spec.py` fails.register_option_loader("speechModels", load_speech_models)register_option_loader("speechVoices", load_speech_voices)+register_option_loader("speechLanguages", load_speech_languages)+register_option_loader("speechFormats", load_speech_formats)+register_option_loader("speechSampleRates", load_speech_sample_rates)__all__ = ["SpeechToTextNode",diff --git a/server/nodes/speech/_option_loaders.py b/server/nodes/speech/_option_loaders.pyindex 4d922024..1ebca2d6 100644--- a/server/nodes/speech/_option_loaders.py+++ b/server/nodes/speech/_option_loaders.py@@ -55,6 +55,75 @@ async def load_speech_models(params: Dict[str, Any]) -> List[Dict[str, Any]]:return options+async def load_speech_languages(params: Dict[str, Any]) -> List[Dict[str, Any]]:+ """Language codes for the selected provider and direction.++ A provider with a closed set (Sarvam accepts exactly 11 locales, and+ rejects anything else) serves its own list. Everything else falls back to+ the shared shortlist in ``speech_defaults.json`` — Whisper and Deepgram+ accept far more codes than that, so the list is a convenience rather than+ a constraint, and "Auto-detect" leads so the common case is one click.+ """+ direction = _direction_for(params)+ provider = _selected_provider(params, direction)+ if not provider:+ return []++ codes = speech_config.capability(provider, direction, "languages", default=None)+ if not codes:+ codes = speech_config.SPEECH_DEFAULTS.get("common_languages") or []++ options: List[Dict[str, Any]] = [+ {"value": "", "label": "Auto-detect", "description": "Let the provider decide"}+ ]+ options.extend({"value": code, "label": code} for code in codes)+ return options+++async def load_speech_formats(params: Dict[str, Any]) -> List[Dict[str, Any]]:+ """Output containers the selected synthesis provider accepts."""+ provider = _selected_provider(params, speech_config.TTS)+ if not provider:+ return []++ default = speech_config.capability(+ provider, speech_config.TTS, "default_output_format", default=""+ )+ options: List[Dict[str, Any]] = []+ for fmt in speech_config.output_formats(provider):+ option: Dict[str, Any] = {"value": fmt, "label": fmt}+ if fmt == default:+ option["description"] = "Provider default"+ options.append(option)+ return options+++async def load_speech_sample_rates(params: Dict[str, Any]) -> List[Dict[str, Any]]:+ """Sample rates, for the providers that expose the choice at all.++ Empty for providers that do not — the field is gated by+ ``displayOptions`` so it should not be visible in that case anyway, but+ an empty list is the honest answer rather than a fabricated one.+ """+ provider = _selected_provider(params, speech_config.TTS)+ if not provider:+ return []++ rates = speech_config.capability(+ provider, speech_config.TTS, "sample_rates", default=[]+ )+ default = speech_config.capability(+ provider, speech_config.TTS, "default_sample_rate", default=None+ )+ options: List[Dict[str, Any]] = []+ for rate in rates or []:+ option: Dict[str, Any] = {"value": rate, "label": f"{rate} Hz"}+ if rate == default:+ option["description"] = "Provider default"+ options.append(option)+ return options++async def load_speech_voices(params: Dict[str, Any]) -> List[Dict[str, Any]]:"""Voices for the selected synthesis provider.diff --git a/server/nodes/speech/speech_to_text.py b/server/nodes/speech/speech_to_text.pyindex c95247ad..e447c623 100644--- a/server/nodes/speech/speech_to_text.py+++ b/server/nodes/speech/speech_to_text.py@@ -84,6 +84,7 @@ class SpeechToTextParams(BaseModel):language: str = Field(default="",description="Language hint (e.g. en, hi-IN). Leave blank to auto-detect.",+ json_schema_extra={"loadOptionsMethod": "speechLanguages"},)translate: bool = Field(default=False,@@ -104,6 +105,7 @@ class SpeechToTextParams(BaseModel):'untouched — e.g. {"keyterm": ["invoice"]} for Deepgram, ''{"mode": "codemix"} for Sarvam, {"response_format": "text"} for OpenAI.'),+ json_schema_extra={"editor": "json", "rows": 4},)model_config = {"extra": "ignore"}diff --git a/server/nodes/speech/text_to_speech.py b/server/nodes/speech/text_to_speech.pyindex 3fae0a78..5833b05f 100644--- a/server/nodes/speech/text_to_speech.py+++ b/server/nodes/speech/text_to_speech.py@@ -96,6 +96,7 @@ class TextToSpeechParams(BaseModel):"Language or locale code. Required by Sarvam (e.g. hi-IN); ""auto-detected by the others."),+ json_schema_extra={"loadOptionsMethod": "speechLanguages"},)speed: Optional[float] = Field(default=None,@@ -107,10 +108,18 @@ class TextToSpeechParams(BaseModel):output_format: str = Field(default="",description="Audio format. Leave blank for the provider default.",+ json_schema_extra={"loadOptionsMethod": "speechFormats"},)sample_rate: Optional[int] = Field(default=None,- description="Output sample rate in Hz, where the provider supports it.",+ description="Output sample rate in Hz.",+ # Only Sarvam exposes the choice; elsewhere the rate is fixed by+ # `output_format`, so an inert box would imply a control that does+ # not exist.+ json_schema_extra={+ "loadOptionsMethod": "speechSampleRates",+ "displayOptions": {"show": {"provider": ["sarvam"]}},+ },)provider_options: Dict[str, Any] = Field(default_factory=dict,@@ -119,6 +128,7 @@ class TextToSpeechParams(BaseModel):'untouched — e.g. {"stability": 0.6} for ElevenLabs, ''{"pitch": 0.2} for Sarvam, {"instructions": "..."} for OpenAI.'),+ json_schema_extra={"editor": "json", "rows": 4},)model_config = {"extra": "ignore"}diff --git a/server/tests/nodes/test_speech.py b/server/tests/nodes/test_speech.pyindex 0e2577b9..29a0c735 100644--- a/server/tests/nodes/test_speech.py+++ b/server/tests/nodes/test_speech.py@@ -122,18 +122,34 @@ class TestCapabilityResolution:"openai", "gpt-4o-mini-transcribe-2025-12-15") == ["json", "text"]- def test_declared_null_is_distinguishable_from_absent(self):- """Deepgram declares no upload cap; that is a fact, not a gap."""+ def test_declared_null_is_distinguishable_from_absent(self, monkeypatch):+ """"Declared as unknown" and "never configured" are different facts.++ Exercised against a synthetic block rather than a real provider, so+ the mechanism stays tested when a vendor publishes a limit it+ previously did not.+ """from nodes.speech import _config- assert (- _config.capability("deepgram", "stt", "max_upload_bytes", default="ABSENT")- is None- )- assert (- _config.capability("deepgram", "stt", "nonexistent", default="ABSENT")- == "ABSENT"+ monkeypatch.setitem(+ _config.SPEECH_DEFAULTS["providers"],+ "_probe",+ {"stt": {"declared_null": None}},)+ assert _config.capability("_probe", "stt", "declared_null", default="ABSENT") is None+ assert _config.capability("_probe", "stt", "absent", default="ABSENT") == "ABSENT"++ def test_deepgram_limits_match_the_published_ones(self):+ """Both are documented, and the duration one bites in practice.++ An earlier revision asserted Deepgram published no cap at all. It+ does: 2 GB, and a 10-minute synchronous ceiling above which the API+ returns 504 rather than a transcript.+ """+ from nodes.speech import _config++ assert _config.capability("deepgram", "stt", "max_upload_bytes") == 2 * 1024**3+ assert _config.capability("deepgram", "stt", "max_duration_seconds") == 600def test_boolean_capabilities_default_permissive(self):from nodes.speech import _config