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.
- 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.
- 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.
You can install WhispAPI globally using npm or Bun to use it as a CLI tool:
npm install -g whispapi
bun install -g whispapi
Note: Ensure that the package name
whispapi
is correctly published to npm or Bun registry. Replace it if it's different.
Alternatively, clone the repository and install dependencies locally:
git clone https://github.com/yourusername/whispapi.git
cd whispapi
npm install
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.
After installing WhispAPI globally, you can use the whispapi
command in your terminal.
Transcribe an audio or video file and save the transcription in the default txt
format.
whispapi /path/to/audio_or_video_file.mp3
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
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 es
Transcribe a file in Spanish and save the output in JSON format.
whispapi /path/to/file.mp3 -f json -l es
Output:
whispering... please wait, this can take some time...
{
"transcription": "Hola, este es un ejemplo de transcripción."
}
Transcription saved to /path/to/file.json
WhispAPI can be imported and used in your Node.js applications to add transcription capabilities.
If you haven't already, install WhispAPI in your project directory:
npm install whispapi
Or using Bun:
bun add whispapi
Note: Ensure that the package name
whispapi
is correctly published to npm or Bun registry. Replace it if it's different.
Import the whispapi
function from the module and use it with the required parameters.
// 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.js
Output:
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."
}
Transcribes an audio or video file using the WhispAPI service.
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).
- (Promise): Resolves with the transcription text/content.
Throws an error if:
filePath
is not provided.- The file does not exist.
- The file is neither audio nor video based on its extension.
- An invalid
format
is specified. - The transcription API request fails.
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 whispapi
-
Create a New Branch:
git checkout -b feature/your-feature-name
-
Make 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-name
-
Create 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.
This project is licensed under the MIT License.