npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

llamaindex-whisper

v0.0.5

Published

Whisper reader for llamaindex

Downloads

7

Readme

LlamaIndex integration with OpenAI's whisper

Installation

This integrates the LlamaIndexTS project with OpenAI's whisper speech transcription and translation library.

Required libraries

To start, ensure you have whisper and ffmpeg locally:

pip install openai-whisper
brew install ffmpeg

And this package, of course:

npm install llamaindex-whisper

Getting started

Simply import the WhisperReader and load your data. It's that easy!

loadData returns an array of LlamaIndex Document objects. The array always contains one Document with all of the text. (Support for chunking and splitting is a future concern.)

  import { WhisperReader } from "llamaindex-whisper";
  const reader = new WhisperReader();
  const documents = reader.loadData("this-is-water-speech.mp3");
  // => Document(text="Greetings parents and congratulations to Kenyon’s graduating class of 2005…")

Combining that with llamaindex itself:

import { VectorStoreIndex } from "llamaindex";
import { WhisperReader, WhisperDevice, WhisperOutputFormat } from "llamaindex-whisper";

async function main() {
  const whisperReader = new WhisperReader({
    device: WhisperDevice.CPU,
    outputFormat: WhisperOutputFormat.Text,
  });

  const documents = await whisperReader.loadData("./giant-leap.mp3")

  // Split text and create embeddings. Store them in a VectorStoreIndex
  const index = await VectorStoreIndex.fromDocuments(documents);

  // Query the index
  const queryEngine = index.asQueryEngine();
  const response = await queryEngine.query(
    "How big were the step and the leap?"
  );

  // Output response
  console.log(response.toString());
  // => Based on the given context information, the step and the leap are not described in terms of their size or magnitude.
  // Well, you can't win them all…
}

main();

Options

WhisperReader supports a subset of the whisper CLI. Here are the ones supported so far with their defaults:

  model: WhisperModel = WhisperModel.Base;
  temperature: number = 0;
  language: WhisperLanguage = WhisperLanguage.English;
  outputDirectory = ".";
  outputFormat = WhisperOutputFormat.All;
  task: WhisperTask = WhisperTask.Transcribe;
  device: WhisperDevice = WhisperDevice.CUDA;

Model

WhisperModel could be any of the supported whisper models and defaults to Base. English variants are specifically fine-tuned for english processing. The generic models are multilingual:

TinyEnglish
Tiny
BaseEnglish
Base
SmallEnglish
Small
MediumEnglish
Medium
LargeV1
LargeV2
Large

Language

WhisperLanguage has mappings for nearly 100 languages, from Afrikaans to Yoruba. Specifically:

Afrikaans, Albanian, Amharic, Arabic, Armenian, Assamese, Azerbaijani, Bashkir, Basque, Belarusian, Bengali, Bosnian, Breton, Bulgarian, Catalan, Chinese, Croatian, Czech, Danish, Dutch, English, Estonian, Faroese, Finnish, French, Galician, Georgian, German, Greek, Gujarati, HaitianCreole, Hausa, Hawaiian, Hebrew, Hindi, Hungarian, Icelandic, Indonesian, Italian, Japanese, Javanese, Kannada, Kazakh, Khmer, Korean, Lao, Latin, Latvian, Lingala, Lithuanian, Luxembourgish, Macedonian, Malagasy, Malay, Malayalam, Maltese, Maori, Marathi, Mongolian, Myanmar, Nepali, Norwegian, Nynorsk, Occitan, Pashto, Persian, Polish, Portuguese, Punjabi, Romanian, Russian, Sanskrit, Serbian, Shona, Sindhi, Sinhala, Slovak, Slovenian, Somali, Spanish, Sundanese, Swahili, Swedish, Tagalog, Tajik, Tamil, Tatar, Telugu, Thai, Tibetan, Turkish, Turkmen, Ukrainian, Urdu, Uzbek, Vietnamese, Welsh, Yiddish, Yoruba

OutputFormat

WhisperOutputFormat tells whisper the format of the file it writes for transcription. The default is All, which writes one file for each of the supported types. I don't know why they decided on that—I can't imagine it's what people want—so you'll want to specify an output.

All
Text
VTT
SRT
TSV
JSON

Task

WhisperTask can be set to either Transcribe or Translate. Transcription is the default.

Device

WhisperDevice can be either CPU or CUDA. This defaults to CUDA, so take note to swap into CPU mode if your graphics card does not support it.