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.
This commit is contained in:
@@ -19,8 +19,13 @@ RETENTION_INSTRUCTIONS = (DRAFT_MARKER + ' Interrupted assistant output is a sav
|
||||
|
||||
|
||||
|
||||
RESPONSIVE_ASR_PROMPT = 'Transcribe conversational Iranian Persian faithfully, including short informal questions. Do not answer, translate, or add missing words.'
|
||||
|
||||
|
||||
class LocalS2SSettings(BaseModel):
|
||||
local_s2s_enabled: bool = False
|
||||
local_s2s_tts_speed: float = Field(default=1.0, ge=0.25, le=4.0, allow_inf_nan=False)
|
||||
local_s2s_responsive: bool = False
|
||||
local_s2s_retain_interrupted_answers: bool = False
|
||||
local_s2s_endpoint: str = 'ws://local-s2s-engine:8765/v1/realtime'
|
||||
local_s2s_token: SecretStr = SecretStr('')
|
||||
@@ -54,13 +59,19 @@ class LocalS2SSettings(BaseModel):
|
||||
return value
|
||||
|
||||
def components(self):
|
||||
return dict(stt=dict(backend='openai', model=self.local_s2s_stt_model,
|
||||
result = dict(stt=dict(backend='openai', model=self.local_s2s_stt_model,
|
||||
language='fa', response_format='json', final_only=True),
|
||||
llm=dict(backend='chat-completions', model=self.local_s2s_llm_model,
|
||||
max_output_tokens=self.local_s2s_max_output_tokens),
|
||||
tts=dict(backend='openai', model=self.local_s2s_tts_model,
|
||||
voice=self.local_s2s_tts_voice, response_format='pcm', sample_rate=24000),
|
||||
request_timeout_seconds=self.local_s2s_request_timeout_seconds)
|
||||
if self.local_s2s_tts_speed != 1.0:
|
||||
result['tts']['speed'] = self.local_s2s_tts_speed
|
||||
if self.local_s2s_responsive:
|
||||
result['stt'].update(temperature=0, prompt=RESPONSIVE_ASR_PROMPT)
|
||||
result['llm']['stream_batch_sentences'] = 1
|
||||
return result
|
||||
|
||||
|
||||
def setup_session(config):
|
||||
@@ -72,7 +83,7 @@ def setup_session(config):
|
||||
session['max_output_tokens'] = config.local_s2s_max_output_tokens
|
||||
session['audio']['input']['transcription'] = dict(model=config.local_s2s_stt_model, language='fa')
|
||||
session['audio']['output']['voice'] = config.local_s2s_tts_voice
|
||||
session['audio']['output']['speed'] = 1.0
|
||||
session['audio']['output']['speed'] = config.local_s2s_tts_speed
|
||||
if config.local_s2s_retain_interrupted_answers:
|
||||
session['instructions'] += '\n' + RETENTION_INSTRUCTIONS
|
||||
return session
|
||||
@@ -80,7 +91,7 @@ def setup_session(config):
|
||||
|
||||
def effective_identity(components, session):
|
||||
retention = session.get('instructions', '').endswith(RETENTION_INSTRUCTIONS)
|
||||
return dict(engine_revision=UPSTREAM_REVISION, patch_revision='rag-local-s2s-phase3-retain-v1' if retention else PATCH_REVISION,
|
||||
return dict(engine_revision=UPSTREAM_REVISION, patch_revision='rag-local-s2s-responsive-v1' if 'stream_batch_sentences' in components['llm'] else ('rag-local-s2s-phase3-retain-v1' if retention else PATCH_REVISION),
|
||||
contract_revision='rag-local-s2s-phase3-retain-v1' if retention else CONTRACT_REVISION, components=components,
|
||||
effective_config_sha256=sha256(canonical_json(dict(components=components, session=session)).encode()).hexdigest())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user