225 lines
14 KiB
Markdown
225 lines
14 KiB
Markdown
# OpenAI Persian speech Phase 1 implementation and frontend handoff
|
|
|
|
Date: 2026-10-11. Scope: Phase 1 of [the quality plan](../plans/openai-realtime-persian-quality-plan.md).
|
|
Implementation and acceptance are tracked separately in the [baseline report](../evaluation/openai-persian-speech-baseline.json).
|
|
No Phase 2 style/voice or Phase 3 conversation/retrieval change is included.
|
|
|
|
## Configuration and frozen admission
|
|
|
|
The main `python -m app.server` path uses VoiceSettings, the selected provider
|
|
factory and RealtimeAdapter. Gemini's profile, setup and instructions remain
|
|
unchanged. The standalone live_voice_server.py spike is untouched.
|
|
No public DTO, normalized event, database schema or migration changes.
|
|
|
|
OpenAI reservations now include `execution_profile.audio_input`: exact requested
|
|
PCM format, transcription model/language mode/prompt/keywords, server VAD
|
|
threshold/prefix/silence settings and noise reduction. The same validated settings
|
|
produce the adapter session.update. Both VAD ownership flags remain false.
|
|
Readiness requires matching provider acknowledgment, including all configured
|
|
audio fields; conflicting language modes or an automatic idle timeout fail closed.
|
|
Configuration copies are revalidated before the factory opens a connection.
|
|
|
|
The baseline remains whisper-1/fa, no prompt/keywords, VAD threshold 0.5,
|
|
prefix padding 300 ms and silence duration 500 ms, no noise reduction.
|
|
The VAD values previously omitted from the wire are now explicit documented
|
|
defaults. Noise off is explicit null. These are requested settings; the
|
|
deployment's historical acknowledgment/default noise value was not observed.
|
|
No baseline speech accuracy or release acceptance is inferred from defaults.
|
|
|
|
| Setting | Default | Validation |
|
|
| --- | --- | --- |
|
|
| OPENAI_REALTIME_ASR_MODEL | whisper-1 | whisper-1 or gpt-transcribe; no silent substitution |
|
|
| OPENAI_REALTIME_ASR_LANGUAGE | fa | fa/en/null; must be null for gpt-transcribe |
|
|
| OPENAI_REALTIME_ASR_LANGUAGES | [] | Unique fa/en list; gpt-transcribe only |
|
|
| OPENAI_REALTIME_ASR_PROMPT | empty | At most 1024 characters |
|
|
| OPENAI_REALTIME_ASR_KEYWORDS | [] | At most 64 unique, nonblank terms, 100 characters each; no angle brackets or line breaks; gpt-transcribe only |
|
|
| OPENAI_REALTIME_VAD_THRESHOLD | 0.5 | Finite 0..1 |
|
|
| OPENAI_REALTIME_VAD_PREFIX_PADDING_MS | 300 | Integer 0..2000 |
|
|
| OPENAI_REALTIME_VAD_SILENCE_DURATION_MS | 500 | Integer 100..2000 |
|
|
| OPENAI_REALTIME_NOISE_REDUCTION | null | null, near_field or far_field |
|
|
|
|
The integer ranges and text/list caps are local engineering limits, not provider
|
|
performance guarantees. These fields are server configuration; no client selectors.
|
|
Environment `null` parses as Python None only for the new optional ASR language/noise fields. JSON arrays are required for list settings.
|
|
|
|
Explicit ASR candidate, without changing any defaults:
|
|
|
|
```dotenv
|
|
OPENAI_REALTIME_ASR_MODEL=gpt-transcribe
|
|
OPENAI_REALTIME_ASR_LANGUAGE=null
|
|
OPENAI_REALTIME_ASR_LANGUAGES=["fa","en"]
|
|
OPENAI_REALTIME_ASR_PROMPT="Iranian Persian technical support with English terminology."
|
|
OPENAI_REALTIME_ASR_KEYWORDS=["PCM16LE","API"]
|
|
OPENAI_REALTIME_VAD_THRESHOLD=0.5
|
|
OPENAI_REALTIME_VAD_PREFIX_PADDING_MS=300
|
|
OPENAI_REALTIME_VAD_SILENCE_DURATION_MS=500
|
|
OPENAI_REALTIME_NOISE_REDUCTION=null
|
|
```
|
|
|
|
Operators must maintain literal vocabulary and a short context description.
|
|
Never insert expected answers, retrieved document text or display transcripts.
|
|
The transcription stream is display guidance; the conversation model consumes
|
|
audio independently. The runtime never turns display transcripts into input.
|
|
|
|
Official schema verified on 2026-10-11:
|
|
[Realtime transcription](https://developers.openai.com/api/docs/guides/realtime-transcription)
|
|
supports gpt-transcribe after committed turns over WebSocket.
|
|
[Client-event schema](https://developers.openai.com/api/reference/resources/realtime/client-events)
|
|
supports gpt-transcribe, plural languages, keywords, server VAD and near/far-field
|
|
noise reduction. Do not send singular and plural language fields together.
|
|
This verifies documented schema support, not account availability or real quality.
|
|
No transcription delay, semantic VAD or separate transcription service was added.
|
|
The [deprecation notice](https://developers.openai.com/api/docs/deprecations) still
|
|
lists gpt-realtime-mini retirement on January 20, 2027 and whisper-1 on February
|
|
26, 2027. Defaults were retained for a controlled baseline; no replacement was
|
|
promoted or assumed available.
|
|
|
|
Replay still returns the original session/request identity after configuration
|
|
changes. Stream admission compares the frozen snapshot before opening the
|
|
provider. OpenAI reservations missing audio_input or differing from today's
|
|
effective profile are unusable; no snapshot is repaired or rewritten. Reconcile
|
|
and close the old reservation, then create a fresh reservation/request ID.
|
|
The existing active-session busy rule and ownership checks still apply.
|
|
|
|
## Speech assets and scoring
|
|
|
|
The [manifest](../evaluation/openai-persian-speech-manifest.json) contains 30
|
|
planning slots: ten each quiet/office/moderate noise, split 20 development and
|
|
ten held-out, with three planned speaker slots and coverage requirements.
|
|
Every recording, speaker identity, consent, duration and device field is empty.
|
|
Speaker slots are assignments to collect, not claims of actual participants.
|
|
|
|
A native human must fill the [annotation template](../evaluation/openai-persian-speech-annotations.json)
|
|
from approved real recordings, including reference text, reviewer identity,
|
|
critical number/date/identifier/negation literals, pause and utterance boundaries.
|
|
Critical facts have objects `{fact_id, kind, literal}`. Approve labels before
|
|
comparison; do not derive them from provider transcripts. Keep held-out samples
|
|
out of tuning and prompt/vocabulary construction.
|
|
|
|
Copy the [observation template](../evaluation/openai-persian-speech-observations.template.json)
|
|
to a separate measured report. Record the exact full execution profile and its
|
|
SHA256 using sorted-key, compact, UTF-8 JSON. Each observation repeats that digest
|
|
and supplies its session reference, final transcript, human critical-fact results,
|
|
completion delay (speech end to final transcript), response latency (speech end
|
|
to first output audio), segmentation/truncation counts, usage/cost availability
|
|
and classified failure notes. Critical results map fact_id to a human boolean;
|
|
provide critical_reviewed_by. Never fabricate absent observations or zero latency.
|
|
Use relative recording paths from the manifest directory and hashes of originals.
|
|
|
|
```powershell
|
|
.venv/Scripts/python -m app.score_speech --manifest docs/evaluation/openai-persian-speech-manifest.json --annotations docs/evaluation/openai-persian-speech-annotations.json --observations path/to/measured-observations.json --split held_out
|
|
```
|
|
|
|
The scorer is offline and makes no provider calls. It emits JSON to stdout;
|
|
exit 0 means its ASR gate passed, 1 means failed/blocked, 2 means invalid evidence.
|
|
It normalizes NFC, Arabic/Persian ya/kaf, decimal digit forms, punctuation and
|
|
whitespace/ZWNJ. It preserves numeric/identifier separators, signs, percentages,
|
|
repeated words and negation. It reports edit counts and condition-weighted WER,
|
|
empty/truncated transcripts, segmentation errors and p50/p95 completion/response
|
|
latency. Critical facts use separate human judgments, not substring heuristics.
|
|
Incomplete references/recordings/review/cohort prerequisites cannot pass.
|
|
A scorer pass never closes frontend or real-speech product acceptance.
|
|
|
|
No real-provider work is authorized by this handoff. Before each batch record
|
|
explicit authorized models, maximum sessions, total audio duration, tool calls,
|
|
embedding calls and currency/spend ceiling, then track actual consumption.
|
|
First compare baseline ASR versus candidate with identical recordings,
|
|
conversation model, voice, instructions, VAD and noise. Freeze the chosen short
|
|
prompt/vocabulary before held-out evaluation. Next compare 500 versus 800 ms
|
|
silence with threshold/prefix and selected ASR fixed. Finally compare noise
|
|
off/near_field for confirmed headsets or off/far_field for confirmed laptop
|
|
microphones. Use fresh sessions and the same utterance order/context each time:
|
|
gpt-transcribe uses earlier transcribed turns as context.
|
|
|
|
Report WER <=10% quiet, <=15% office, <=25% moderate noise; zero designated
|
|
quiet/office critical errors; segmentation, empty/truncated transcripts,
|
|
completion delay, response latency, exact full profiles/digests and unavailable
|
|
usage/cost. Investigate >20% comparable p95 latency regression before promotion.
|
|
Classify capture, assembly, ASR, segmentation and direct audio understanding
|
|
independently; improved ASR does not establish improved model understanding.
|
|
|
|
## Actual frontend handoff and acceptance checklist
|
|
|
|
The repository contains developer examples, not the separately maintained
|
|
production frontend. No actual browser/hardware acceptance or frontend repair is
|
|
claimed. The receiving developer must record frontend build/commit, backend
|
|
build/commit, browser/version, OS, capture device and all observed results.
|
|
|
|
Use the runnable [VoiceTranscripts helper](../../examples/voice-transcripts.js)
|
|
with existing VoiceClient onEvent callbacks:
|
|
|
|
```javascript
|
|
import {VoiceTranscripts} from './voice-transcripts.js';
|
|
import {VoiceClient} from './voice-client.js';
|
|
const display = new VoiceTranscripts();
|
|
const client = new VoiceClient(event => {
|
|
const row = display.apply(event);
|
|
if (row) renderTranscript(row.turn_ref, row.role, row.text, row.status);
|
|
// Handle other existing events as before.
|
|
});
|
|
// At the start of each fresh session: display.reset().
|
|
```
|
|
|
|
The callback retains the unchanged application events. Partial text appends by
|
|
turn_ref AND role; a completed full text replaces that row. Never append finals
|
|
or assign late finals to the latest active turn. Identical words in distinct
|
|
deltas are real content. Provider identity replay is handled by the backend; the
|
|
public transcript has no replay ID, so clients must not deduplicate by text.
|
|
Interruption retains assistant text marked interrupted; delayed user finals
|
|
remain displayable on their original turn. An absent transcript stays unavailable.
|
|
The helper is bounded to 512 rows/65536 characters per row and resets between
|
|
sessions. Adapt capacity to the actual renderer without retaining production
|
|
recordings or durable full voice history.
|
|
|
|
All items below are **not_run** until the receiving frontend records evidence:
|
|
|
|
- [ ] Capture PCM16LE, mono, 24000 Hz; verify bytes with an approved test fixture,
|
|
device native rate and actual resampling. Reject mismatches before capture.
|
|
- [ ] Verify positive/negative sample endian/sign, clipping and gain with actual
|
|
devices. Record browser echoCancellation/noiseSuppression/autoGainControl.
|
|
- [ ] Verify frame sizes <=9600 bytes, queue <=96000 bytes/100 messages, capture
|
|
frame loss/gaps and sustained sending, including at least 30 seconds silence.
|
|
- [ ] Verify output PCM format, sample-based playback progress per audio_ref,
|
|
queued versus heard audio, flush final progress and cleanup during stop.
|
|
- [ ] Verify repeated words, distinct equal partial deltas, full-final replacement,
|
|
T1 completion after T2 partial, role separation and unavailable transcripts.
|
|
- [ ] Verify interrupted assistant text stays interrupted; late user completion
|
|
updates only its original turn; revoked/closed sessions deliver no text.
|
|
- [ ] Verify response audio starts without waiting for ASR completion.
|
|
- [ ] For each device, collect designated natural-pause cases (including pauses
|
|
around numbers, negation, self-corrections and English terms) at 500/800 ms;
|
|
mark actual split/merge errors against human utterance boundaries.
|
|
- [ ] Exercise interruption during generation/retrieval and after generation with
|
|
queued playback; accurate heard-position truncation, terminal confirmation,
|
|
no stale output and one durable close remain required.
|
|
- [ ] Exercise fresh reservation, configuration change/replay, legacy rejection,
|
|
stop/disconnect/reconciliation, selection/access revocation and provider error.
|
|
- [ ] Record held-out condition WER/critical gates and capture/assembly failures
|
|
separately, with exact frozen profiles and latency comparisons.
|
|
- [ ] Record receiving developer and human reviewer signoff. Only then mark
|
|
frontend acceptance passed; Phase 1 remains open while any gate is unrun.
|
|
|
|
## Verification record
|
|
|
|
Exact executed checks and limitations are maintained in the baseline report.
|
|
Unit/mock/scorer fixtures are synthetic regression inputs, not quality evidence.
|
|
Applied revisions, retrieval/calibration policy, cancellation classifier,
|
|
commit fencing, response-release barriers and heard-position truncation remain.
|
|
The only runtime tightening rejects malformed transcription event types or
|
|
post-completion user deltas; display text is never a response-release condition.
|
|
|
|
Final affected validation: 361 provider-free voice/configuration/scorer/frontend
|
|
regressions passed; 82 isolated PostgreSQL profile/replay/authorization/terminal
|
|
and revocation cases passed with zero skips. The broader database run reported a
|
|
failure and was interrupted after sustained lack of progress; its full acceptance
|
|
is unverified. Broad ordinary-suite attempts also failed existing deadline and
|
|
responsiveness assertions. No assertion was weakened and no unrelated product
|
|
repair was made. Exact attempts and final results are in the baseline report.
|
|
The task-owned database container and anonymous storage were removed.
|
|
|
|
Final full provider-free attempt: 1874 passed, three existing Windows symlink
|
|
skips, one existing GeminiVision extraction 100-ms deadline failure. Both
|
|
parameter variants passed afterward in isolation (2 passed); no cause is
|
|
established and the full run is not represented as green. These checks do not
|
|
establish real microphone, ASR, hardware, frontend or deployment acceptance.
|