UNPKG

@omnimedia/omnitool

Version:

open source video processing tools

33 lines 1.3 kB
import { Comrade } from "@e280/comrade"; import { coalesce, queue, sub } from "@e280/stz"; import { prepAudio } from "./parts/prep-audio.js"; export async function makeTranscriber({ driver, spec, workerUrl, onLoading }) { const onReport = sub(); const onTranscription = sub(); const thread = await Comrade.thread({ label: "OmnitoolSpeechTranscriber", workerUrl, setupHost: () => ({ loading: async (loading) => onLoading(loading), deliverReport: async (report) => onReport.pub(report), deliverTranscription: async (transcription) => onTranscription.pub(transcription), }), }); await thread.work.prepare(spec); return { transcribe: queue(async (info) => { const { source, language } = info; const { audio, duration } = await prepAudio(driver, source); const detachCallbacks = coalesce(onReport(info.onReport), onTranscription(info.onTranscription)); const result = await thread.work.transcribe({ duration, language, audio: audio.buffer, }); detachCallbacks(); return result; }), dispose: thread.terminate() }; } //# sourceMappingURL=transcriber.js.map