Skip to content

node : add language detection support #3190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

danbev
Copy link
Collaborator

@danbev danbev commented May 26, 2025

This commit add support for language detection in the Whisper Node.js addon example.

The motivation for this is that currently there does not seem to be a way to get the language detected by whisper.

Examples usage:

$ node examples/addon.node/index.js --language='en' \
    --model='models/ggml-base.bin' \
    --fname_inp='samples/jfk.wav' \
    --detect_language=true
whisperParams = {
  language: 'en',
  model: 'models/ggml-base.bin',
  fname_inp: 'samples/jfk.wav',
  use_gpu: true,
  flash_attn: false,
  no_prints: true,
  comma_in_time: false,
  translate: true,
  no_timestamps: false,
  detect_language: true,
  audio_ctx: 0,
  max_len: 0,
  progress_callback: [Function: progress_callback]
}

{ language: 'en' }

And if the language option is set to "auto":

{
  language: 'en',
  transcription: [
    [
      '00:00:00.000',
      '00:00:07.600',
      ' And so my fellow Americans, ask not what your country can do for you,'
    ],
    [
      '00:00:07.600',
      '00:00:10.600',
      ' ask what you can do for your country.'
    ]
  ]
}

danbev added 2 commits May 26, 2025 16:03
This commit add support for language detection in the Whisper Node.js
addon example.

The motivation for this is that currently there does not seem to be a
way to get the language detected by whisper.

Examples usage:
```console
$ node examples/addon.node/index.js --language='en' \
    --model='models/ggml-base.bin' \
    --fname_inp='samples/jfk.wav' \
    --detect_language=true
whisperParams = {
  language: 'en',
  model: 'models/ggml-base.bin',
  fname_inp: 'samples/jfk.wav',
  use_gpu: true,
  flash_attn: false,
  no_prints: true,
  comma_in_time: false,
  translate: true,
  no_timestamps: false,
  detect_language: true,
  audio_ctx: 0,
  max_len: 0,
  progress_callback: [Function: progress_callback]
}

{ language: 'en' }
```
danbev added 2 commits May 29, 2025 07:58
This commit updates the node example to return an object instead of an
array as the results.

The motivation for this change is to enable the inclusion of the
detected language in the result, in addition to the transcription
segments.

For example, when using the `detect_language` option, the result will
now be:
```console
{ language: 'en' }
```

And if the `language` option is set to "auto", it will also return:
```console
{
  language: 'en',
  transcription: [
    [
      '00:00:00.000',
      '00:00:07.600',
      ' And so my fellow Americans, ask not what your country can do for you,'
    ],
    [
      '00:00:07.600',
      '00:00:10.600',
      ' ask what you can do for your country.'
    ]
  ]
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant