UNPKG

@pr0gramm/fluester

Version:

Node.js bindings for OpenAI's Whisper. Optimized for CPU.

67 lines (66 loc) 2.75 kB
import { type ModelName } from "./model.js"; import { type LanguageDetectionResult, type TranscriptLine } from "./transcript.js"; export { createWebVttString } from "./webvtt.js"; export { convertFileToProcessableFile } from "./ffmpeg.js"; export interface WhisperClientOptionsBase { /** Path to the whisper executable */ executablePath?: string; } export interface WhisperClientOptionsWithModelName extends WhisperClientOptionsBase { /** * Name of model stored in `node_modules/@pr0gramm/fluester/lib/whisper.cpp/models` * * The name you entered when downloading the model. */ modelName: ModelName; } export interface WhisperClientOptionsWithModelPath extends WhisperClientOptionsBase { modelPath: string; } export type WhisperClientOptions = WhisperClientOptionsWithModelName | WhisperClientOptionsWithModelPath; export interface WhisperOptions { whisperOptions?: FlagTypes; sourceLanguage?: string; signal?: AbortSignal; } export interface WhisperClient { /** * @param filePath The audio file to translate. **Audio file must be in a processable format.** * @param options * @returns English translation of the audio file. If it's already english, it will be a transcription. * @throws If the model provided at {@link createWhisperClient} is not found. */ translate: (filePath: string, options?: WhisperOptions) => Promise<TranscriptLine[]>; /** * @param filePath The audio file to transcribe. **Audio file must be in a processable format.** * @param options * @returns Transcription of the audio file. * @throws If the model provided at {@link createWhisperClient} is not found. */ transcribe: (filePath: string, options?: WhisperOptions) => Promise<TranscriptLine[]>; /** * Detects the language of the audio file * @param filePath The audio file to detect the language of. * @returns `undefined` if there was an error or the language could not be detected. * @remarks Audio file must be in a processable format just like when using {@link translate}. * @throws If the model provided at {@link createWhisperClient} is not found. */ detectLanguage: (filePath: string) => Promise<LanguageDetectionResult | undefined>; } export declare function createWhisperClient(options: WhisperClientOptions): WhisperClient; export interface CppCommandTypes { filePath: string; modelName?: ModelName; modelPath?: string; options?: FlagTypes; } export interface FlagTypes { /** Build TXT? */ generateTxt?: boolean; /** Build SRT? */ generateSubtitles?: boolean; /** Build VTT? */ generateVtt?: boolean; timestampSize?: number; wordTimestamps?: boolean; }