(raw: unknown)
| 43 | } |
| 44 | |
| 45 | function detectJsonFormat(raw: unknown): TranscriptFormat { |
| 46 | if (raw && typeof raw === "object" && !Array.isArray(raw)) { |
| 47 | const obj = raw as Record<string, unknown>; |
| 48 | if (obj.transcription && Array.isArray(obj.transcription)) return "whisper-cpp"; |
| 49 | if (obj.words && Array.isArray(obj.words)) return "openai"; |
| 50 | } |
| 51 | if (Array.isArray(raw) && raw[0]?.text !== undefined && raw[0]?.start !== undefined) { |
| 52 | return "words-json"; |
| 53 | } |
| 54 | throw new Error( |
| 55 | "Unrecognized JSON transcript format. Expected whisper.cpp (transcription[].tokens), " + |
| 56 | "OpenAI API (words[]), or normalized ([{text, start, end}]).", |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | // --------------------------------------------------------------------------- |
| 61 | // Parsers |
no outgoing calls
no test coverage detected