-
Notifications
You must be signed in to change notification settings - Fork 102
Add OGG support and dynamically query supported audio formats #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import AVFoundation | |
| import Combine | ||
| import CoreMedia | ||
| import Foundation | ||
| import UniformTypeIdentifiers | ||
|
|
||
| /// Result of a transcription operation | ||
| struct TranscriptionResult: Identifiable, Sendable, Codable { | ||
|
|
@@ -67,6 +68,29 @@ final class MeetingTranscriptionService: ObservableObject { | |
| @Published var error: String? | ||
| @Published var result: TranscriptionResult? | ||
|
|
||
| // MARK: - Supported Formats | ||
|
|
||
| /// File extensions the OS can actually decode, queried dynamically from AVFoundation. | ||
| /// Filtered to audio/video types only — excludes subtitles, playlists, etc. | ||
| static let supportedFileExtensions: Set<String> = { | ||
| let avTypes = AVURLAsset.audiovisualTypes() | ||
| let extensions = avTypes.compactMap { fileType -> String? in | ||
| guard let utType = UTType(fileType.rawValue) else { return nil } | ||
| guard utType.conforms(to: .audio) || utType.conforms(to: .movie) else { return nil } | ||
| return utType.preferredFilenameExtension | ||
| } | ||
| return Set(extensions) | ||
|
Comment on lines
+76
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new allowlist is built from Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any clever way to do this filtering or would I need to hardcode the list of non-transcribable types?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found a way to filter dynamically, commit
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are the descriptions for the remaining 36, they are all containers that can genuinely have audio: |
||
| }() | ||
|
|
||
| /// Content types accepted by the file picker — broad categories so the OS filters naturally. | ||
| static let allowedContentTypes: [UTType] = [.audio, .movie] | ||
|
|
||
| /// User-facing description of supported formats (curated for readability). | ||
| static let supportedFormatsDescription = "Supported: WAV, MP3, M4A, OGG, MP4, MOV, and more" | ||
|
|
||
| /// Error copy shown when a dropped file is not accepted. | ||
| static let dropErrorCopy = "Accepted file types: WAV, MP3, M4A, OGG, MP4, MOV, and more." | ||
|
|
||
| /// Share the ASR service instance to avoid loading models twice | ||
| private let asrService: ASRService | ||
|
|
||
|
|
@@ -159,11 +183,10 @@ final class MeetingTranscriptionService: ObservableObject { | |
|
|
||
| // Check file extension | ||
| let fileExtension = fileURL.pathExtension.lowercased() | ||
| let supportedFormats = ["wav", "mp3", "m4a", "ogg", "aac", "flac", "aiff", "caf", "mp4", "mov"] | ||
|
|
||
| guard supportedFormats.contains(fileExtension) else { | ||
| guard Self.supportedFileExtensions.contains(fileExtension) else { | ||
| throw TranscriptionError | ||
| .fileNotSupported("Format .\(fileExtension) not supported. Supported: \(supportedFormats.joined(separator: ", "))") | ||
| .fileNotSupported("Format .\(fileExtension) not supported. \(Self.supportedFormatsDescription)") | ||
| } | ||
|
|
||
| // Get audio duration for progress display | ||
|
|
@@ -181,7 +204,8 @@ final class MeetingTranscriptionService: ObservableObject { | |
| DebugLogger.shared.warning("Could not determine audio duration: \(error.localizedDescription)", source: "MeetingTranscriptionService") | ||
| } | ||
|
|
||
| let isVideoContainer = ["mp4", "mov"].contains(fileExtension) | ||
| let isVideoContainer = UTType(filenameExtension: fileExtension) | ||
| .map { $0.conforms(to: .movie) } ?? false | ||
|
|
||
| if provider.prefersNativeFileTranscription && !isVideoContainer { | ||
| self.currentStatus = duration > 0 ? "Transcribing audio (\(Int(duration))s)..." : "Transcribing audio..." | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Including every
UTTypethat conforms to.movieinsupportedFileExtensionsadmits many new video extensions (e.g.avi,mts,vob) that were previously rejected, but downstream logic still treats onlymp4/movas video containers (isVideoContainer = ["mp4", "mov"]). For providers withprefersNativeFileTranscription == true, those newly admitted movie files now take the native path instead of the buffered video path and can fail at runtime, turning a deterministicfileNotSupportedrejection into a later transcription/conversion error.Useful? React with 👍 / 👎.