Whisper to support directories/wildcards?

could we do something like this, where audio file could actually be a “file” that is:

  • a filename {you already support this}
  • several filenames {you already support this}
  • a wildcard
  • a folder {to do recursively}

I haven’t written the part for filelists, but here’s a nice pattern for adapting a “file” parameter to work as filename/wildcard/folder:

def process_file(file_path, subdir):
    [main program guts here]

def process_files(file_paths):
    for file_path in file_paths:
    #optional ostprocess_files(".")

def process_directory(directory):
    for subdir, dirs, files in os.walk(directory):
        for filename in files:
            filepath = subdir + os.sep + filename
            process_file(filepath, subdir)
        #optional: postprocess_files(subdir)

def main():
    path = sys.argv[1]

    if os.path.isdir(path):                                                     # If path is a directory
        print(f"\nProcessing files in directory: {path}\n")
    elif os.path.isfile(path):                                                  # If path is a file
        print(f"\nProcessing file: {path}\n")
        process_file(path, subdir=".")
    elif '*' in path:                                                           # If path is a wildcard
        files = glob.glob(path)
        print(f"\nProcessing files: {files}\n")
    else:                                                                       # If path is neither a file, nor a directory, nor a wildcard
        print("\nInvalid argument. Please enter a valid file path, wildcard, or directory.\n")