SPB Git

Repository Public License

SettingsView.swift 10.5 KB 164 lines swift

1//2//  ORIX Audio3//  File: ORIXAudio/Features/Settings/SettingsView.swift4//  Description: Settings: recording defaults, inputs, on-device speech models, intelligence availability, privacy lock, appearance, about.5//6//  Author: Simon-Pierre Boucher7//  Contact: contact@spboucher.ai8//9import ORIXAudioCore10import SwiftUI1112struct SettingsView: View {13    @Environment(AppModel.self) private var model14    @Environment(AppSettings.self) private var settings15    @State private var inputs: [AudioInputDescription] = []16    @State private var locales: [Locale] = []17    @State private var path: TranscriptionPath?18    @State private var downloading = false19    @State private var downloadProgress = 0.020    @State private var downloadError: String?2122    var body: some View {23        @Bindable var settings = settings24        Form {25            Section {26                Picker("Default quality", selection: $settings.defaultPreset) { ForEach(RecordingPreset.allCases) { Text(PresetText.name($0)).tag($0) } }27                Picker("Microphone", selection: $settings.preferredInputID) {28                    Text("Automatic").tag(String?.none)29                    ForEach(inputs) { Text("\($0.name) · \($0.typeLabel)").tag(String?.some($0.id)) }30                }31                Toggle("Allow Bluetooth microphones", isOn: $settings.allowBluetoothMicrophone)32                Toggle("Raw input (no system processing)", isOn: $settings.rawInput)33                Toggle("Analyze new recordings automatically", isOn: $settings.analyzeAutomatically)34            } header: { Text("Recording").foregroundStyle(ORIX.Palette.textSecondary) } footer: {35                Text("Bluetooth hands-free microphones are narrow-band (8–16 kHz). Raw input turns off the system's automatic gain and voice processing; levels will be lower.").foregroundStyle(ORIX.Palette.textSecondary)36            }3738            Section {39                Picker("Language", selection: $settings.transcriptionLocaleIdentifier) {40                    if !locales.contains(where: { $0.identifier(.bcp47) == settings.transcriptionLocaleIdentifier }) {41                        Text(Locale.current.localizedString(forIdentifier: settings.transcriptionLocaleIdentifier) ?? settings.transcriptionLocaleIdentifier).tag(settings.transcriptionLocaleIdentifier)42                    }43                    ForEach(locales, id: \.identifier) { Text(Locale.current.localizedString(forIdentifier: $0.identifier) ?? $0.identifier).tag($0.identifier(.bcp47)) }44                }45                LabeledContent("On this device") { Text(pathDescription).multilineTextAlignment(.trailing).foregroundStyle(pathTint) }46                if path == .speechTranscriberNeedsDownload {47                    if downloading { ProgressRow(title: "Downloading speech model…", progress: downloadProgress) }48                    else { Button("Download the speech model", systemImage: "arrow.down.circle") { Task { await download() } } }49                }50                if let downloadError { Text(downloadError).font(.footnote).foregroundStyle(ORIX.Palette.record) }51                Toggle("Live text while recording", isOn: $settings.liveTranscription)52            } header: { Text("Transcription").foregroundStyle(ORIX.Palette.textSecondary) } footer: {53                Text("Transcription runs entirely on this device. The language list comes from the system; languages it doesn't report are not offered. Downloading a speech model needs a network connection once — a model is downloaded, audio is never uploaded.").foregroundStyle(ORIX.Palette.textSecondary)54            }5556            Section {57                LabeledContent("Apple Foundation Models") { Text(MeetingIntelligence.availability == .available ? "Available" : "Unavailable").foregroundStyle(MeetingIntelligence.availability == .available ? ORIX.Palette.good : ORIX.Palette.warning) }58                Text(CoreText.explain(MeetingIntelligence.availability)).font(.footnote).foregroundStyle(ORIX.Palette.textSecondary)59            } header: { Text("Summaries and questions").foregroundStyle(ORIX.Palette.textSecondary) }6061            Section {62                Toggle("Require Face ID / passcode to open", isOn: $settings.requireBiometrics)63                Toggle("Remind me about consent", isOn: Binding(get: { !settings.hasAcknowledgedConsent }, set: { settings.hasAcknowledgedConsent = !$0 }))64                NavigationLink("Privacy", destination: PrivacyView())65            } header: { Text("Privacy").foregroundStyle(ORIX.Palette.textSecondary) }6667            Section {68                Picker("Appearance", selection: $settings.appearance) { Text("System").tag(AppearanceMode.system); Text("Dark").tag(AppearanceMode.dark); Text("Light").tag(AppearanceMode.light) }69                Picker("Waveform", selection: $settings.waveformStyle) {70                    Text("Frequency colours").tag(WaveformStyle.spectral); Text("Band shares").tag(WaveformStyle.bands)71                    Text("Amplitude").tag(WaveformStyle.amplitude); Text("RMS and peak envelope").tag(WaveformStyle.envelope)72                }73                Picker("Spectrogram palette", selection: $settings.palette) { ForEach(Colormap.allCases) { Text(CoreText.name($0)).tag($0) } }74            } header: { Text("Display").foregroundStyle(ORIX.Palette.textSecondary) } footer: {75                Text("“Band shares”, “Monochrome”, “High Contrast” and “Colorblind-friendly” don't rely on hue to carry information.").foregroundStyle(ORIX.Palette.textSecondary)76            }7778            Section {79                LabeledContent("Version", value: "\(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "") (\(Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? ""))")80                LabeledContent("Free storage", value: Formatters.bytes(LibraryFiles.freeDiskSpace()))81                NavigationLink("How measurements are made", destination: MethodologyView())82            } header: { Text("About").foregroundStyle(ORIX.Palette.textSecondary) } footer: { Text("ORIX Audio — Hear Everything. Understand More.").foregroundStyle(ORIX.Palette.textSecondary) }83        }84        .navigationTitle("Settings")85        .task {86            inputs = AudioSessionManager.shared.availableInputs87            locales = await TranscriptionEngine.supportedLocales()88            await refreshPath()89        }90        .onChange(of: settings.transcriptionLocaleIdentifier) { _, _ in Task { await refreshPath() } }91    }9293    private var pathDescription: String {94        switch path {95        case .speechTranscriber: String(localized: "Ready (SpeechTranscriber)")96        case .speechTranscriberNeedsDownload: String(localized: "Speech model not installed")97        case .legacyOnDevice: String(localized: "Ready (on-device recognizer)")98        case .unavailable: String(localized: "Not available on-device")99        case nil: "…"100        }101    }102    private var pathTint: Color { path == .speechTranscriber || path == .legacyOnDevice ? ORIX.Palette.good : ORIX.Palette.warning }103104    private func refreshPath() async { path = await TranscriptionEngine.path(for: Locale(identifier: settings.transcriptionLocaleIdentifier)) }105106    private func download() async {107        downloading = true; downloadError = nil; downloadProgress = 0108        do { try await TranscriptionEngine.installModel(for: Locale(identifier: settings.transcriptionLocaleIdentifier)) { p in Task { @MainActor in downloadProgress = p } } }109        catch { downloadError = CoreText.describe(error) }110        downloading = false111        await refreshPath()112    }113}114115struct PrivacyView: View {116    var body: some View {117        List {118            Section("What ORIX Audio does") {119                Label("Stores recordings, transcripts, notes and analysis only on this device.", systemImage: "internaldrive")120                Label("Transcribes with Apple's on-device speech recognition. It never falls back to a server.", systemImage: "waveform.badge.mic")121                Label("Summarizes with Apple's on-device language model, when the device supports it.", systemImage: "sparkles")122                Label("Shows an indicator on the Lock Screen whenever a recording is in progress.", systemImage: "lock.display")123            }124            Section("What it never does") {125                Label("No account, no sign-in.", systemImage: "person.crop.circle.badge.xmark")126                Label("No analytics, no advertising, no tracking.", systemImage: "chart.bar.xaxis")127                Label("No uploads. The app contains no networking code of its own.", systemImage: "icloud.slash")128                Label("No hidden or covert recording.", systemImage: "eye.slash")129            }130            Section("Good to know") {131                Text("Recordings are included in your device backups (iCloud or computer) like other app data, if you use them.")132                Text("Files are encrypted by iOS and become readable after the first unlock following a restart. This is what allows recording to continue while the device is locked.")133                Text("Downloading a speech model, when you ask for it, is done by iOS and transfers a model to your device, not your audio.")134            }135        }136        .navigationTitle("Privacy")137    }138}139140struct MethodologyView: View {141    var body: some View {142        List {143            Section("Levels") {144                Text("All levels are relative to digital full scale: 0 dBFS is the largest value the file can hold. They are not sound pressure levels — a phone microphone is not a calibrated instrument.")145            }146            Section("Spectrum") {147                Text("Amplitude: a sine wave reads its peak amplitude (a full-scale sine reads 0 dBFS), corrected for the analysis window.")148                Text("Power: mean-square power per bin. PSD: power per hertz, normalised by the window's noise bandwidth.")149            }150            Section("Waveform colours") {151                Text("Each bar's colour comes from an FFT of the audio at that moment, split into seven bands. It is a measurement, not decoration.")152                BandLegend().padding(.vertical, 6).listRowBackground(ORIX.Palette.plot)153            }154            Section("Loudness") {155                Text("Integrated, momentary and short-term loudness follow ITU-R BS.1770-4 (K-weighting, gating). Loudness range follows EBU Tech 3342. True peak uses 4× oversampling.")156            }157            Section("Estimates") {158                Text("Speech activity, pauses and speaking rate are heuristic estimates based on energy in the voice band. Findings are indications, not forensic or medical conclusions.")159            }160        }161        .navigationTitle("Measurements")162    }163}164
Files main
Menu

Theme