Repository Public
1// SP Notes Core2// File: Sources/SPNotesAPI/AudioModels.swift3// Description: Models of voice transcription (API-NEXT-AI §6): the state of the transcript of an audio attachment.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import Foundation89/// `status` of a transcription.10public enum TranscriptionStatus {11 /// Never requested.12 public static let none = "none"13 /// Poll every 2–3 s.14 public static let pending = "pending"15 public static let done = "done"16 public static let failed = "failed"17}1819/// One segment of a transcript — exactly an entry of the `audio` node's `transcript` attr.20public struct AudioTranscriptSegment: Codable, Sendable, Equatable {21 /// Seconds from the start.22 public var t: Double23 public var text: String24}2526/// The AI summary of a transcript — the `audio` node's `summary` attr.27public struct AudioTranscriptSummary: Codable, Sendable, Equatable {28 public var text: String?29 public var decisions: [String]?30 public var tasks: [String]?31 public var model: String?32 public var at: Date?33}3435/// `GET /api/audio/<attachmentId>` and `POST /api/audio/<attachmentId>/transcribe`. When `status` becomes `done`36/// **the client** copies `transcript`, `engine`/`model` and `summary` into the `audio` node and saves the page.37public struct AudioTranscription: Codable, Sendable, Equatable {38 public var attachmentId: String39 /// `TranscriptionStatus`.40 public var status: String41 public var transcript: [AudioTranscriptSegment]?42 /// The whole text.43 public var text: String?44 /// What actually produced the transcript (`openai`).45 public var engine: String?46 public var model: String?47 public var language: String?48 /// Seconds.49 public var duration: Double?50 /// `false` = a text-only model: one segment at `t: 0`.51 public var segments: Bool?52 public var summary: AudioTranscriptSummary?53 /// The reason when `failed`; when `done`, a non-nil value means the summary could not be produced.54 public var error: String?55 public var costUsd: Double?56 public var requestedAt: Date?57 public var finishedAt: Date?58 /// Answer of `transcribe` only: whether a job was queued by this call (`false`: a transcript exists or is pending).59 public var queued: Bool?60 public var jobId: String?6162 public var isPending: Bool { status == TranscriptionStatus.pending }63 public var isDone: Bool { status == TranscriptionStatus.done }6465 /// A reasonable value for the `audio` node's `transcriptEngine` attr: `<engine>:<model>`.66 public var engineLabel: String? {67 guard let engine else { return model }68 return model.map { "\(engine):\($0)" } ?? engine69 }70}71