Improve classroom readback tolerance

This commit is contained in:
itsrubberduck
2026-07-27 12:29:37 +02:00
parent d6b2b328f6
commit b470d805f8
3 changed files with 159 additions and 24 deletions

View File

@@ -75,6 +75,10 @@ export function normalizeForMatch(value: string): string {
.trim()
}
function compactForMatch(value: string): string {
return normalizeForMatch(value).replace(/\s+/g, '')
}
/** Convert spoken ATC English back to written tokens (digits, runway letters,
* collapsed callsign codes). Returned text is also `normalizeForMatch`-safe. */
export function denormalizeSpokenAtc(input: string): string {
@@ -295,6 +299,8 @@ export function matchTranscriptionToFields(
): SttMatchResult {
const normalized = normalizeForMatch(transcription)
const denormalized = normalizeForMatch(denormalizeSpokenAtc(transcription))
const normalizedCompact = compactForMatch(normalized)
const denormalizedCompact = compactForMatch(denormalized)
const matches: Record<string, string> = {}
// Per-field diagnostic keyed by field.key (output in original order below).
const reportByKey: Record<string, SttFieldReport> = {}
@@ -321,12 +327,19 @@ export function matchTranscriptionToFields(
for (const cand of candidates) {
if (!cand) continue
const compactCandidate = compactForMatch(cand)
if (candidateMatches(normalized, cand)) {
report.matched = true; report.matchedVia = cand; report.view = 'raw'; break
}
if (candidateMatches(denormalized, cand)) {
report.matched = true; report.matchedVia = cand; report.view = 'spoken'; break
}
if (compactCandidate.length >= 2 && normalizedCompact.includes(compactCandidate)) {
report.matched = true; report.matchedVia = cand; report.view = 'raw'; break
}
if (compactCandidate.length >= 2 && denormalizedCompact.includes(compactCandidate)) {
report.matched = true; report.matchedVia = cand; report.view = 'spoken'; break
}
if (field.isCallsign && cand.length >= 4
&& (callsignMatches(normalized, cand) || callsignMatches(denormalized, cand))) {
report.matched = true; report.matchedVia = cand; report.view = 'callsign'; break