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

Merged
merged 1 commit into from
Jun 2, 2025

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.'
    ]
  ]
}

@zdm
Copy link

zdm commented Jun 1, 2025

@ggerganov

Could you please merge this PR?
We tested it - it works without any problems.
It improves nodejs addon and make possible to retrieve detected language.

This commit add support for language detection in the Whisper Node.js
addon example. It also updates the node addon 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.'
    ]
  ]
}
```
@danbev danbev force-pushed the node-detect-language branch from 0513f87 to 4a217ce Compare June 2, 2025 03:34
@danbev danbev requested a review from ggerganov June 2, 2025 06:28
@danbev danbev merged commit b505539 into ggml-org:master Jun 2, 2025
55 checks passed
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.

3 participants