whispapi
v0.0.13
Published
whisper api call
Readme
WhispAPI
WhispAPI is a versatile Node.js tool that allows you to transcribe audio and video files using the WhispAPI service. It can be used both as a Command-Line Interface (CLI) tool and as a reusable module in other Node.js applications. Whether you're a developer looking to integrate transcription capabilities into your app or a user needing a quick transcription tool from the terminal, WhispAPI has you covered.
Table of Contents
Features
- Dual Functionality: Use WhispAPI as a CLI tool or integrate it as a module in your applications.
- Flexible Output Formats: Supports multiple transcription output formats including
txt,json,srt, andvtt. - Language Support: Specify the language for transcription.
- Spinner Feedback: Provides visual feedback during the transcription process using a spinner.
- Error Handling: Gracefully handles errors and provides informative messages.
Installation
Prerequisites
- Node.js: Ensure you have Node.js (version 14 or later) installed. You can download it from the Node.js Official Website.
- Bun (Optional): If you prefer using Bun, ensure it's installed. You can get it from the Bun Official Website.
Install via npm or Bun
You can install WhispAPI globally using npm or Bun to use it as a CLI tool:
Using npm:
npm install -g whispapiUsing Bun:
bun install -g whispapiNote: Ensure that the package name
whispapiis correctly published to npm or Bun registry. Replace it if it's different.
Install from Source
Alternatively, clone the repository and install dependencies locally:
git clone https://github.com/yourusername/whispapi.git
cd whispapi
npm installUsage
WhispAPI can be used in two primary ways:
- As a CLI Tool: Transcribe files directly from the terminal.
- As a Module: Integrate transcription functionality into your Node.js applications.
As a CLI Tool
After installing WhispAPI globally, you can use the whispapi command in your terminal.
Basic Usage
Transcribe an audio or video file and save the transcription in the default txt format.
whispapi /path/to/audio_or_video_file.mp3Specifying Output Format
Use the -f or --format flag to specify the desired output format. Supported formats are txt, json, srt, and vtt.
whispapi -f json /path/to/file.mp3 Specifying Language
Use the -l or --language flag to specify the language code for transcription. The default language is English (en).
whispapi /path/to/file.mp3 -l esFull Example
Transcribe a file in Spanish and save the output in JSON format.
whispapi /path/to/file.mp3 -f json -l esOutput:
whispering... please wait, this can take some time...
{
"transcription": "Hola, este es un ejemplo de transcripción."
}
Transcription saved to /path/to/file.jsonAs a Module
WhispAPI can be imported and used in your Node.js applications to add transcription capabilities.
Installation
If you haven't already, install WhispAPI in your project directory:
npm install whispapiOr using Bun:
bun add whispapiNote: Ensure that the package name
whispapiis correctly published to npm or Bun registry. Replace it if it's different.
Importing and Using WhispAPI
Import the whispapi function from the module and use it with the required parameters.
Example
// anotherApp.js
import { whispapi } from 'whispapi'; // Adjust the import path as needed
async function transcribeFile() {
const filePath = '/path/to/audio_or_video_file.mp3';
const format = 'json'; // Optional: 'txt', 'json', 'srt', 'vtt'
const language = 'en'; // Optional: language code
try {
const transcription = await whispapi(filePath, format, language);
console.log('Transcription:', transcription);
} catch (error) {
console.error('Error during transcription:', error.message);
}
}
transcribeFile();Running the Example:
node anotherApp.jsOutput:
whispering... please wait, this can take some time...
{
"transcription": "Hello, this is an example of transcription."
}
Transcription saved to /path/to/file.json
Transcription: {
"transcription": "Hello, this is an example of transcription."
}API Reference
whispapi(filePath, format, language)
Transcribes an audio or video file using the WhispAPI service.
Parameters
filePath(string): Required. The path to the audio or video file to transcribe.format(string): Optional. The desired output format. Supported formats:'txt'(default)'json''srt''vtt'
language(string): Optional. The language code for transcription. Default is'en'(English).
Returns
- (Promise): Resolves with the transcription text/content.
Errors
Throws an error if:
filePathis not provided.- The file does not exist.
- The file is neither audio nor video based on its extension.
- An invalid
formatis specified. - The transcription API request fails.
Contributing
Contributions are welcome! Please follow these steps:
Fork the Repository: Click the "Fork" button at the top-right corner of the repository page.
Clone Your Fork:
git clone https://github.com/yourusername/whispapi.git cd whispapiCreate a New Branch:
git checkout -b feature/your-feature-nameMake Changes: Implement your feature or bug fix.
Commit Your Changes:
git commit -m "Add feature: your feature description"Push to Your Fork:
git push origin feature/your-feature-nameCreate a Pull Request: Navigate to the original repository and click on "New Pull Request."
Please ensure that your code follows the project's coding standards and includes appropriate documentation.
License
This project is licensed under the MIT License.
