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:
@@ -4,6 +4,7 @@ Persistent reservations include failed requests. Exactly two attempts per compon
|
||||
cover construction probes and one turn. No retries or ledger reset are supported.
|
||||
"""
|
||||
from decimal import Decimal
|
||||
import base64
|
||||
from io import BytesIO
|
||||
import json
|
||||
from pathlib import Path
|
||||
@@ -51,11 +52,21 @@ def validate_request(request):
|
||||
request.url.scheme == 'https' and request.url.path in (
|
||||
'/api/v1/audio/speech', '/api/v1/audio/transcriptions', '/api/v1/chat/completions'))
|
||||
if stage == 'transcriptions':
|
||||
message = BytesParser(policy=default).parsebytes(
|
||||
('Content-Type: '+request.headers['content-type']+'\r\nMIME-Version: 1.0\r\n\r\n').encode()+request.content)
|
||||
fields = {p.get_param('name', header='content-disposition'): p.get_payload(decode=True)
|
||||
for p in message.iter_parts()}
|
||||
require(fields['model'].decode() == MODELS[stage] and fields['language'] == b'fa')
|
||||
if request.headers.get('content-type','').startswith('application/json'):
|
||||
from app.modules.voice.local_s2s import RESPONSIVE_ASR_PROMPT
|
||||
data=json.loads(request.content)
|
||||
require(set(data)=={'model','language','response_format','temperature','input_audio','provider'} and
|
||||
data['model']==MODELS[stage] and data['language']=='fa' and data['response_format']=='json' and
|
||||
type(data['temperature']) is int and data['temperature']==0 and
|
||||
data['provider']=={'options':{'groq':{'prompt':RESPONSIVE_ASR_PROMPT}}} and
|
||||
set(data['input_audio'])=={'data','format'} and data['input_audio']['format']=='wav')
|
||||
fields={'file':base64.b64decode(data['input_audio']['data'],validate=True)}
|
||||
else:
|
||||
message = BytesParser(policy=default).parsebytes(
|
||||
('Content-Type: '+request.headers['content-type']+'\r\nMIME-Version: 1.0\r\n\r\n').encode()+request.content)
|
||||
fields = {p.get_param('name', header='content-disposition'): p.get_payload(decode=True)
|
||||
for p in message.iter_parts()}
|
||||
require(fields['model'].decode() == MODELS[stage] and fields['language'] == b'fa')
|
||||
with wave.open(BytesIO(fields['file']), 'rb') as audio:
|
||||
require(audio.getnchannels() == 1 and audio.getsampwidth() == 2 and
|
||||
audio.getcomptype() == 'NONE' and
|
||||
|
||||
Reference in New Issue
Block a user