Files
rag-technical-docs-assistant/docs/evaluation/local-s2s/phase4-browser-engine.py
amirhosein mazaheri 628aec8def feat(voice): implement local S2S responsiveness candidate and direct TTS routing
Add local S2S responsiveness candidate pinning ASR options and sentence-at-a-time generation. Route speech synthesis directly to OpenAI API for fluent Persian phonetics with gpt-4o-mini-tts-2025-12-15. Add responsiveness, budget carry, and browser watch unit tests along with acceptance benchmarks and evaluation evidence.
2026-10-17 13:02:41 +03:30

40 lines
1.6 KiB
Python

"""Use the actual engine launcher with the browser-only admission transport."""
import importlib.util
from pathlib import Path
from threading import Thread
from services.local_s2s.components import ComponentServer
import services.local_s2s.lifecycle as lifecycle
from services.local_s2s.engine import main
spec=importlib.util.spec_from_file_location('browser_budget','/checks/phase4-browser-budget.py')
module=importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
def start_components(key, timeout, **options):
if os.environ.get('LOCAL_S2S_TTS_MODEL') == 'google/gemini-3.8-flash-lite-tts':
transport=module.BrowserBudget(Path('/evidence'))
class OwnedGateway(ComponentServer):
async def _run(self):
try:
await super()._run()
finally:
await transport.close_owned()
gateway=OwnedGateway(key,port=8766,transport=transport,timeout=timeout,**options)
else:
gateway=ComponentServer(key,port=8766,timeout=timeout,**options)
thread=Thread(target=gateway.serve_forever,daemon=True)
thread.start()
if not gateway.ready.wait(5):
raise RuntimeError('BROWSER_GATEWAY_NOT_READY')
return gateway,thread
lifecycle.start_components=start_components
# The key is mounted only into this engine, never Compose environment/API/browser.
import os
os.environ['OPENROUTER_API_KEY']=Path('/secret/openrouter-test.key').read_text().strip()
if Path('/secret/openai-test.key').exists():
os.environ['OPENAI_API_KEY']=Path('/secret/openai-test.key').read_text().strip()
raise SystemExit(main())