Evidence-backed proposals from full source code audit (2026-03-11). Each entry references the specific file and line that motivates the change.
Problem: TTS.validate_ssml (templates/tts.py:362–364) calls self.format_speak_tags(utterance, False) and self.format_speak_tags(utterance) but discards both return values. The SSML wrapping/stripping logic therefore has no effect; the raw utterance is returned unchanged.
Fix: Assign the return value:
if not self.ssml_tags or "speak" not in self.ssml_tags:
utterance = self.format_speak_tags(utterance, False)
elif self.ssml_tags and "speak" in self.ssml_tags:
utterance = self.format_speak_tags(utterance)Impact: High — correctness bug. All SSML handling in TTS.execute is silently broken.
Problem: format_speak_tags line 346 uses to_speak.lstrip("<speak>").rstrip("</speak>"). lstrip/rstrip strip individual characters from a character set, not substrings. Text beginning with the characters <, s, p, e, a, k, > will be incorrectly mutilated.
Fix:
return to_speak.removeprefix("<speak>").removesuffix("</speak>")removeprefix/removesuffix are available since Python 3.9 and this package already requires Python 3.10+.
Impact: Medium — latent correctness bug; may manifest with SSML-heavy plugins.
Problem: OpenVoiceOSPlugin.plugin_type (plugin_entry.py:197–251) calls find_stt_plugins(), find_tts_plugins(), find_wake_word_plugins(), find_audio_service_plugins() on each call to the property before self._plugtype is set. A single plugin.json access chains through clazz → is_installed → plugin_type, triggering four full entry-point scans.
Fix: After self._plugtype is determined (any branch), the result is already cached. The issue is that self._plugtype starts as None and the property must be fully re-evaluated to find it is still None. Document explicitly that once set _plugtype is never cleared, and add an early-return guard:
if self._plugtype is not None:
return self._plugtypeThis is already the intent of line 183 (if not self._plugtype) — but the guard only short-circuits if a previous call completed. The fix is already implicit; the remaining issue is the first-access cost. Consider a dedicated _discover_plugin_type() method called once from __init__ if plugin_type is provided.
Impact: Medium — performance. On systems with many installed plugins, first-time access is expensive.
Problem: find_plugins._errored (utils/init.py:206) and _iter_entrypoints._warnings (utils/init.py:273) are plain list objects. Membership checks (if x not in list) are O(n). Both lists grow unbounded over the lifetime of the process.
Fix:
find_plugins._errored = set()
# In find_plugins:
find_plugins._errored.add(entry_point)_iter_entrypoints._warnings = set()
# In _iter_entrypoints:
_iter_entrypoints._warnings.add(e.name)Impact: Low effort, meaningful performance gain on systems with many broken plugins.
Problem: VADEngine.extract_speech (templates/vad.py:104) returns bytes only if the unvoiced threshold is crossed. If the input audio ends before that, the function returns None implicitly. The current return annotation says bytes.
Fix: Change annotation to Optional[bytes] and add a docstring note:
def extract_speech(self, audio: bytes) -> Optional[bytes]:
"""...Returns None if no speech segment was detected."""Callers should guard: result = vad.extract_speech(audio); if result: ....
Impact: Medium — prevents TypeError in downstream callers that concatenate or write the result.
Problem: The property at plugin_entry.py:183–255 is 70+ lines with six cascading inference steps and 24 near-identical string membership tests.
Fix: Extract:
def _infer_plugin_type_from_string(s: str) -> Optional[PluginTypes]:
s = s.lower()
if "tts" in s:
return PluginTypes.TTS
elif "stt" in s:
return PluginTypes.STT
elif "word" in s:
return PluginTypes.WAKEWORD
elif "audio" in s:
return PluginTypes.AUDIO
return NoneThen reduce the property to six calls to this helper.
Impact: Low effort — dramatically improves readability and reduces lines by ~40.
Problem: installation.py:35 calls requests.get(f'https://pypi.org/search/...') with no timeout. A slow/hung PyPI server will block the caller indefinitely. The HTML scraping approach is also fragile.
Fix:
response = requests.get(url, timeout=10)Long term: use the PyPI JSON API (https://pypi.org/pypi/{package}/json) for structured data instead of HTML parsing.
Impact: Medium — prevents process hang; improves reliability.
Problem: tts.py, stt.py, wakewords.py, audio.py, g2p.py, vad.py, etc. each define the same two functions:
def find_X_plugins() -> Dict[str, Type[X]]:
from ovos_plugin_manager.utils import find_plugins
return find_plugins(PluginTypes.X)
def load_X_plugin(module_name: str) -> Type[X]:
from ovos_plugin_manager.utils import load_plugin
return load_plugin(module_name, PluginTypes.X)This pattern is duplicated ~12 times. A generic factory function would eliminate the boilerplate:
def make_plugin_finder(plug_type: PluginTypes):
def find():
return find_plugins(plug_type)
return findImpact: Medium — reduces maintenance burden when new plugin types are added.
Problem: stt.py:91 uses assert stt_config.get('lang') is not None which is disabled under -O (optimised) Python.
Fix:
if stt_config.get('lang') is None:
raise ValueError("STT config missing required 'lang' key")Impact: Low effort — correctness in optimised deployments.
Problem: tts.py:174 and wakewords.py:162 call os.listdir(VOICES_FOLDER) / os.listdir(WW_FOLDER) without checking directory existence, raising FileNotFoundError when voice/WW configs have never been scanned.
Fix: Guard with:
if not os.path.isdir(VOICES_FOLDER):
continue # or return {}Impact: Low — prevents crash on first run or clean install.
Problem: templates/embeddings.py:211–496 has a 285-line if/elif chain with 30+ distance metrics. It is untestable in isolation, hard to extend, and imports scipy.stats conditionally inside branches.
Fix: Use a registry pattern:
_METRICS: Dict[str, Callable] = {
"cosine": _cosine_distance,
"euclidean": _euclidean_distance,
...
}
def distance(self, a, b, metric="cosine", **kwargs) -> float:
if metric not in _METRICS:
raise ValueError(f"Unsupported metric: {metric}")
return _METRICS[metric](a, b, **kwargs)Move scipy imports to module level inside try/except ImportError.
Impact: Medium — makes individual metrics unit-testable and the method readable.
Problem: templates/tts.py:690–695 catches Exception and does pass, discarding the error entirely. Resource leaks (e.g. unclosed audio device) will be invisible.
Fix:
except Exception:
LOG.exception("Error stopping TTS playback")Impact: Low effort — greatly improves debuggability.
Problem: Six locations use bare except: (skills.py:174, utils/config.py:105, ocp.py:71, installation.py:64, templates/solvers.py:276, templates/audio.py:257). This swallows SystemExit, KeyboardInterrupt, and GeneratorExit.
Fix: Replace all bare except: with except Exception and add LOG.exception(...) where not already present.
Impact: Low effort — prevents critical errors from being hidden during shutdown sequences.
Problem: thirdparty/solvers.py line 1 contains # TODO - delete this file in next major release. It carries a BSD-3 license header inconsistent with the rest of the repo (Apache-2.0), and templates/solvers.py fires a deprecation warning on import.
Fix: Schedule removal in the next major version bump. Until then, ensure CHANGELOG.md and MAINTENANCE_REPORT.md document the deprecation timeline clearly.
Impact: Low short-term — reduces code surface and license ambiguity.