Skip to content

Commit

Permalink
Add --audio-folder cli argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachNagengast committed Apr 18, 2024
1 parent 1d376e3 commit 076b670
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Sources/WhisperKitCLI/CLIArguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import ArgumentParser
struct CLIArguments: ParsableArguments {
@Option(help: "Paths to audio files")
var audioPath = [String]()

@Option(help: "Path to a folder containing audio files")
var audioFolder: String?

@Option(help: "Path of model files")
var modelPath: String?
Expand Down
15 changes: 15 additions & 0 deletions Sources/WhisperKitCLI/Transcribe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ struct Transcribe: AsyncParsableCommand {
throw ValidationError("Invalid language code \"\(language)\". Supported languages: \(Constants.languages.values)")
}
}

if cliArguments.audioPath.isEmpty {
guard let audioFolder = cliArguments.audioFolder else {
throw ValidationError("Either audioPath or audioFolder must be provided.")
}
let fileManager = FileManager.default
let audioExtensions = ["mp3", "wav", "m4a", "flac", "aiff", "aac", "ogg"]
let audioFiles = try fileManager.contentsOfDirectory(atPath: audioFolder)
.filter { fileName in
let fileExtension = fileName.lowercased().components(separatedBy: ".").last
return audioExtensions.contains(fileExtension ?? "")
}

cliArguments.audioPath = audioFiles.map { audioFolder + "/" + $0 }
}
}

mutating func run() async throws {
Expand Down

0 comments on commit 076b670

Please sign in to comment.