1.0.29 • Published 10 months ago

@tech9app/whisper.js v1.0.29

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Whisper.js

npm version

The Whisper library is a powerful tool that offers a convenient way to transcribe or translate audio files using Node.js. It leverages the capabilities of the Whisper C++ library, which is responsible for performing the underlying audio processing tasks.

By utilizing native Node.js addons, the Whisper library seamlessly integrates with Node.js applications.

Pre-requisites

  • C++ Compiler: You will need a compatible C++ compiler installed on your system. Ensure that you have a C++ compiler installed. Refer to the documentation of your operating system or compiler for installation instructions.

  • CMake: CMake is required for building the whisper.cpp library. Make sure you have CMake installed on your system. You can download CMake from the official website: https://cmake.org

Installation

To use the Whisper library, follow these steps:

  1. Ensure you have Node.js installed on your machine. You can download it from the official Node.js website: https://nodejs.org

  2. Open your terminal or command prompt.

  3. Navigate to your project directory.

  4. Run the following command to install the Whisper library:

npm install @tech9app/whisper.js

Usage

To transcribe or translate an audio file using the Whisper library, follow these steps:

  1. Import the necessary types and the whisper function from the Whisper library:

    import { WhisperParams, SpeechData, whisper } from '@tech9app/whisper.js';
  2. Define the parameters for the Whisper process by creating an instance of WhisperParams. This object contains various options and settings for the transcription or translation process. For example:

    const whisperParams: WhisperParams = {
      language: 'en',
      model: '/path/to/models',
      fname_inp: '/path/to/input/file.wav',
      output_txt: true,
    };
  3. Call the whisper function, passing the whisperParams as an argument. The whisper function returns a promise that resolves to an array of SpeechData objects or null if the process fails. For example:

    const speechData: SpeechData[] | null = await whisper(whisperParams);
  4. Handle the result of the whisper process as needed. The result is an array of SpeechData objects, where each object represents a segment of speech. Each SpeechData object contains the start and end timestamps and the corresponding speech content.

Note: Make sure to handle any potential errors or exceptions during the process.

API Reference

Type Definitions

WhisperParams

An interface representing the parameters for the Whisper process. It includes the following properties:

ParameterDescriptionDefault Value
n_threadsThe number of threads to use for processingSystem-dependent
n_processorsThe number of processors to use for processing1
offset_t_msThe offset time in milliseconds0
offset_nThe offset value0
duration_msThe duration in milliseconds0
max_contextThe maximum context value-1
max_lenThe maximum length0
best_ofThe best of value5
beam_sizeThe beam size-1
word_tholdThe word threshold0.01
entropy_tholdThe entropy threshold2.4
logprob_tholdThe log probability threshold-1.0
speed_upWhether to enable speed-up optimizationfalse
translateWhether to enable translationfalse
diarizeWhether to enable diarizationfalse
output_txtWhether to output as textfalse
output_vttWhether to output as VTTfalse
output_srtWhether to output as SRTfalse
output_wtsWhether to output as WTSfalse
output_csvWhether to output as CSVfalse
print_specialWhether to print special charactersfalse
print_colorsWhether to print with colorsfalse
print_progressWhether to print progress informationfalse
no_timestampsWhether to exclude timestampsfalse
languageThe language to use for processingundefined
promptThe initial promptundefined
model (required)The path to the model file-
fname_inp (required)The path to the input audio file-
fname_outThe path to the output file-

SpeechData

A type representing the speech data of a segment. It includes the following properties:

FieldDescription
startThe start timestamp of the segment
endThe end timestamp of the segment
speechThe speech content of the segment

Functions

Whisper

The main function of the Whisper library. It processes audio based on the provided parameters and returns a promise that resolves to an array of SpeechData objects or null.

whisper(params: WhisperParams): Promise<Array<SpeechData> | null>

Examples

Here's an example usage of the Whisper library:

import { WhisperParams, SpeechData, whisper } from '@tech9app/whisper.js';

const whisperParams: WhisperParams = {
  language: 'en',
  model: '/path/to/models',
  fname_inp: '/path/to/input/file.wav',
  output_txt: true,
};

whisper(whisperParams).then((result: Array<SpeechData> | null) => {
  console.log('Result from whisper:', result);
});

In this example, the whisperParams object specifies the parameters for the Whisper process, such as the language, model path, input file path, and output format. The whisper function is called with these parameters, and the resulting promise is handled to obtain the transcribed speech segments.

Download Models

Whisper.js Download Utility

This utility allows you to download a model using Whisper.js.

Usage

The Whisper.js Download Utility supports the following options:

  • -m, --modelName <modelName>: Specify the model name.
  • -p, --storagePath <storagePath>: Specify the storage path.
  • -h, --help: Display help for the command.

To use the Whisper.js Download Utility, make sure you have Node.js installed on your system. Then, open your terminal and run the following command:

npx @tech9app/whisper.js download -m <modelName> -p <storagePath>

Replace <modelName> with the desired model name and <storagePath> with the desired storage path.

List of Models

ModelDiskRAM
tiny75 MB~390 MB
tiny.en75 MB~390 MB
base142 MB~500 MB
base.en142 MB~500 MB
small466 MB~1.0 GB
small.en466 MB~1.0 GB
medium1.5 GB~2.6 GB
medium.en1.5 GB~2.6 GB
large-v12.9 GB~4.7 GB
large2.9 GB~4.7 GB

Examples

Download the "base.en" model and store it in the "models" directory:

npx @tech9app/whisper.js download -m base.en -p models

License

This library is released under the MIT License. See the LICENSE file for more details.

1.0.18

10 months ago

1.0.17

11 months ago

1.0.16

11 months ago

1.0.22

10 months ago

1.0.21

10 months ago

1.0.20

10 months ago

1.0.26

10 months ago

1.0.25

10 months ago

1.0.24

10 months ago

1.0.23

10 months ago

1.0.29

10 months ago

1.0.28

10 months ago

1.0.27

10 months ago

1.0.15

11 months ago

1.0.14

11 months ago

1.0.12

11 months ago

1.0.13

11 months ago

1.0.11

11 months ago

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago