Skip to content

Commit

Permalink
Merge pull request #43 from silvioprog/detected-spoken-language
Browse files Browse the repository at this point in the history
feat: detected spoken language (fix #40)
  • Loading branch information
JacobLinCool authored Aug 28, 2024
2 parents 2987b73 + b898a98 commit 028208a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-poems-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"smart-whisper": minor
---

Detected spoken language
6 changes: 6 additions & 0 deletions src/binding/transcribe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ class TranscribeWorker : public Napi::AsyncProgressQueueWorker<int> {
confidence = confidence / (tokens - skips);
}

segment.Set(
"lang",
Napi::String::New(Env(), whisper_lang_str(whisper_full_lang_id_from_state(state))));
segment.Set("confidence", Napi::Number::New(Env(), confidence));
segment.Set("tokens", tokens_array);
}
Expand Down Expand Up @@ -304,6 +307,9 @@ class TranscribeWorker : public Napi::AsyncProgressQueueWorker<int> {
confidence = confidence / (tokens - skips);
}

segment.Set("lang",
Napi::String::New(
Env(), whisper_lang_str(whisper_full_lang_id_from_state(state))));
segment.Set("confidence", Napi::Number::New(Env(), confidence));
segment.Set("tokens", tokens_array);
}
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export interface TranscribeSimpleResult {
*/
export interface TranscribeDetailedResult<TokenTimestamp extends boolean>
extends TranscribeSimpleResult {
/** The detected spoken language. */
lang: string;
/** The confidence level of the transcription, calculated by the average probability of the tokens. */
confidence: number;
/** The tokens generated during the transcription process. */
Expand Down

0 comments on commit 028208a

Please sign in to comment.