Skip to content

Commit e8cc6f6

Browse files
authored
Merge pull request #118 from binarykitchen/feature/improved-logging
Improve logging and add test case
2 parents b24838e + 06b509d commit e8cc6f6

16 files changed

+454
-80
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
dist
33
.env
4+
example/mother_teresa.wav.vtt

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "cpp/whisper.cpp"]
2+
path = cpp/whisper.cpp
3+
url = https://github.com/ggerganov/whisper.cpp.git

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Node.js bindings for OpenAI's Whisper model.
1414
- Translate from source language to english (Optional)
1515
- Convert audio format to wav to support whisper model
1616

17-
1817
## Installation
1918

2019
1. Install make tools
@@ -40,6 +39,8 @@ sudo apt install build-essential
4039

4140
## Usage/Examples
4241

42+
See `example/index.ts` (can be run with `$ npm run test`)
43+
4344
```javascript
4445
import path from 'path'
4546
import { nodewhisper } from 'nodejs-whisper'
@@ -50,9 +51,9 @@ const filePath = path.resolve(__dirname, 'YourAudioFileName')
5051
await nodewhisper(filePath, {
5152
modelName: 'base.en', //Downloaded models name
5253
autoDownloadModelName: 'base.en', // (optional) autodownload a model if model is not present
53-
verbose: false, // (optional) output more dubugging information
5454
removeWavFileAfterTranscription: false, // (optional) remove wav file once transcribed
5555
withCuda: false // (optional) use cuda for faster processing
56+
logger: console // (optional) Logging instance, defaults to console
5657
whisperOptions: {
5758
outputInCsv: false, // get output result in csv file
5859
outputInJson: false, // get output result in json file
@@ -89,11 +90,11 @@ const MODELS_LIST = [
8990
```
9091
interface IOptions {
9192
modelName: string
92-
verbose?: boolean
9393
removeWavFileAfterTranscription?: boolean
9494
withCuda?: boolean
9595
autoDownloadModelName?: string
9696
whisperOptions?: WhisperOptions
97+
logger?: Console
9798
}
9899
99100
interface WhisperOptions {

cpp/whisper.cpp

example/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import path from 'node:path'
2+
import { nodewhisper } from '../src/index'
3+
4+
// Copied from https://www.wavsource.com/people/famous.htm
5+
const AUDIO_FILE = 'mother_teresa.wav'
6+
7+
// Need to provide exact path to your audio file.
8+
const filePath = path.resolve(__dirname, AUDIO_FILE)
9+
10+
async function convert() {
11+
try {
12+
await nodewhisper(filePath, {
13+
modelName: 'base.en',
14+
autoDownloadModelName: 'base.en',
15+
whisperOptions: {
16+
outputInVtt: true,
17+
// Default is 20 which is too long
18+
timestamps_length: 14,
19+
},
20+
})
21+
} catch (exc) {
22+
console.error(exc)
23+
}
24+
}
25+
26+
void convert()

example/mother_teresa.wav

431 KB
Binary file not shown.

0 commit comments

Comments
 (0)