sherpa-onnx-node 1.12.21 → 1.12.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/addon.js CHANGED
@@ -1,3 +1,5 @@
1
+ /** @typedef {import('./types').WaveObject} WaveObject */
2
+
1
3
  const os = require('os');
2
4
  const path = require('path');
3
5
 
@@ -64,3 +66,27 @@ if (!found) {
64
66
 
65
67
  throw new Error(msg)
66
68
  }
69
+
70
+ /**
71
+ * Read a wave file from disk.
72
+ * @function module.exports.readWave
73
+ * @param {string} filename
74
+ * @param {boolean} [enableExternalBuffer=true]
75
+ * @returns {WaveObject}
76
+ */
77
+
78
+ /**
79
+ * Read a wave from binary buffer.
80
+ * @function module.exports.readWaveFromBinary
81
+ * @param {Uint8Array} data - Binary contents of a wave file.
82
+ * @param {boolean} [enableExternalBuffer=true]
83
+ * @returns {WaveObject}
84
+ */
85
+
86
+ /**
87
+ * Write a wave file to disk.
88
+ * @function module.exports.writeWave
89
+ * @param {string} filename
90
+ * @param {WaveObject} obj - { samples: Float32Array, sampleRate: number }
91
+ * @returns {boolean}
92
+ */
package/audio-tagg.js CHANGED
@@ -1,20 +1,39 @@
1
+ /** @typedef {import('./types').AudioTaggingConfig} AudioTaggingConfig */
2
+ /** @typedef {import('./types').AudioEvent} AudioEvent */
3
+ /** @typedef {import('./types').AudioTaggingHandle} AudioTaggingHandle */
4
+ /** @typedef {import('./non-streaming-asr').OfflineStream} OfflineStream */
5
+
1
6
  const addon = require('./addon.js');
2
7
  const non_streaming_asr = require('./non-streaming-asr.js');
3
8
 
9
+ /**
10
+ * AudioTagging utility.
11
+ * @class
12
+ */
4
13
  class AudioTagging {
14
+ /**
15
+ * Create an AudioTagging instance.
16
+ * @param {AudioTaggingConfig} config
17
+ */
5
18
  constructor(config) {
6
19
  this.handle = addon.createAudioTagging(config);
7
20
  this.config = config;
8
21
  }
9
22
 
23
+ /**
24
+ * Create an offline stream bound to this AudioTagging instance.
25
+ * @returns {OfflineStream}
26
+ */
10
27
  createStream() {
11
28
  return new non_streaming_asr.OfflineStream(
12
29
  addon.audioTaggingCreateOfflineStream(this.handle));
13
30
  }
14
31
 
15
- /* Return an array. Each element is
16
- * an object {name: "xxx", prob: xxx, index: xxx};
17
- *
32
+ /**
33
+ * Compute audio tags from an offline stream.
34
+ * @param {OfflineStream} stream - An offline stream created by `AudioTagging.createStream()`.
35
+ * @param {number} [topK=-1] - Return top K results; -1 for all.
36
+ * @returns {AudioEvent[]}
18
37
  */
19
38
  compute(stream, topK = -1) {
20
39
  return addon.audioTaggingCompute(this.handle, stream.handle, topK);
@@ -1,29 +1,60 @@
1
+ /** @typedef {import('./types').KeywordSpotterConfig} KeywordSpotterConfig */
2
+ /** @typedef {import('./types').KeywordResult} KeywordResult */
3
+ /** @typedef {import('./streaming-asr').OnlineStream} OnlineStream */
4
+
1
5
  const addon = require('./addon.js');
2
6
  const streaming_asr = require('./streaming-asr.js');
3
7
 
8
+ /**
9
+ * KeywordSpotter handles keyword detection.
10
+ */
4
11
  class KeywordSpotter {
12
+ /**
13
+ * @param {KeywordSpotterConfig} config
14
+ */
5
15
  constructor(config) {
6
16
  this.handle = addon.createKeywordSpotter(config);
7
17
  this.config = config
8
18
  }
9
19
 
20
+ /**
21
+ * Create an OnlineStream for the spotter.
22
+ * @returns {OnlineStream}
23
+ */
10
24
  createStream() {
11
25
  const handle = addon.createKeywordStream(this.handle);
12
26
  return new streaming_asr.OnlineStream(handle);
13
27
  }
14
28
 
29
+ /**
30
+ * @param {OnlineStream} stream
31
+ * @returns {boolean}
32
+ */
15
33
  isReady(stream) {
16
34
  return addon.isKeywordStreamReady(this.handle, stream.handle);
17
35
  }
18
36
 
37
+ /**
38
+ * Trigger decode on a stream.
39
+ * @param {OnlineStream} stream
40
+ */
19
41
  decode(stream) {
20
42
  addon.decodeKeywordStream(this.handle, stream.handle);
21
43
  }
22
44
 
45
+ /**
46
+ * Reset a stream.
47
+ * @param {OnlineStream} stream
48
+ */
23
49
  reset(stream) {
24
50
  addon.resetKeywordStream(this.handle, stream.handle);
25
51
  }
26
52
 
53
+ /**
54
+ * Get the keyword result for a stream.
55
+ * @param {OnlineStream} stream
56
+ * @returns {KeywordResult}
57
+ */
27
58
  getResult(stream) {
28
59
  const jsonStr = addon.getKeywordResultAsJson(this.handle, stream.handle);
29
60
 
@@ -1,40 +1,128 @@
1
+ /** @typedef {import('./types').OfflineStreamObject} OfflineStreamObject */
2
+ /** @typedef {import('./types').Waveform} Waveform */
3
+ /**
4
+ * @typedef {import('./types').OfflineRecognizerConfig} OfflineRecognizerConfig
5
+ */
6
+ /**
7
+ * @typedef {import('./types').OfflineRecognizerResult} OfflineRecognizerResult
8
+ */
9
+
1
10
  const addon = require('./addon.js');
2
11
 
12
+ /**
13
+ * Internal symbol to mark async-created recognizers.
14
+ * Not accessible unless someone has a reference to this Symbol.
15
+ */
16
+ const kFromAsyncFactory = Symbol('OfflineRecognizer.fromAsync');
17
+
18
+ /**
19
+ * OfflineStream represents a synchronous offline audio stream.
20
+ */
3
21
  class OfflineStream {
22
+ /**
23
+ * @param {OfflineStreamObject|Object} handle
24
+ */
4
25
  constructor(handle) {
5
26
  this.handle = handle;
6
27
  }
7
28
 
8
- // obj is {samples: samples, sampleRate: sampleRate}
9
- // samples is a float32 array containing samples in the range [-1, 1]
10
- // sampleRate is a number
29
+ /**
30
+ * Accept a chunk of waveform samples.
31
+ * @param {Waveform} obj - { samples: Float32Array, sampleRate: number }
32
+ */
11
33
  acceptWaveform(obj) {
12
- addon.acceptWaveformOffline(this.handle, obj)
34
+ addon.acceptWaveformOffline(this.handle, obj);
13
35
  }
14
36
  }
15
37
 
38
+ /**
39
+ * OfflineRecognizer wraps the native offline recognizer.
40
+ */
16
41
  class OfflineRecognizer {
17
- constructor(config) {
18
- this.handle = addon.createOfflineRecognizer(config);
19
- this.config = config
42
+ /**
43
+ * Constructor (SYNC path).
44
+ *
45
+ * Users call:
46
+ * new OfflineRecognizer(config)
47
+ *
48
+ * Async factory calls this with an internal descriptor.
49
+ *
50
+ * @param {OfflineRecognizerConfig | Object} configOrInternal
51
+ */
52
+ constructor(configOrInternal) {
53
+ // ----- async factory path -----
54
+ if (configOrInternal && typeof configOrInternal === 'object' &&
55
+ configOrInternal[kFromAsyncFactory]) {
56
+ this.handle = configOrInternal.handle;
57
+ this.config = configOrInternal.config;
58
+ return;
59
+ }
60
+
61
+ // ----- sync constructor path -----
62
+ this.config = configOrInternal;
63
+ this.handle = addon.createOfflineRecognizer(this.config);
64
+ }
65
+
66
+ /**
67
+ * Create an OfflineRecognizer asynchronously (non-blocking).
68
+ *
69
+ * @param {OfflineRecognizerConfig} config
70
+ * @returns {Promise<OfflineRecognizer>}
71
+ */
72
+ static async createAsync(config) {
73
+ const handle = await addon.createOfflineRecognizerAsync(config);
74
+
75
+ return new OfflineRecognizer({
76
+ [kFromAsyncFactory]: true,
77
+ handle,
78
+ config,
79
+ });
20
80
  }
21
81
 
82
+ /**
83
+ * Create a new OfflineStream bound to this recognizer.
84
+ * @returns {OfflineStream}
85
+ */
22
86
  createStream() {
23
87
  const handle = addon.createOfflineStream(this.handle);
24
88
  return new OfflineStream(handle);
25
89
  }
26
90
 
91
+ /**
92
+ * Replace the recognizer config at runtime.
93
+ * @param {OfflineRecognizerConfig} config
94
+ */
27
95
  setConfig(config) {
96
+ this.config = config;
28
97
  addon.offlineRecognizerSetConfig(this.handle, config);
29
98
  }
30
99
 
100
+ /**
101
+ * Decode an offline stream (synchronous).
102
+ * @param {OfflineStream} stream
103
+ */
31
104
  decode(stream) {
32
105
  addon.decodeOfflineStream(this.handle, stream.handle);
33
106
  }
34
107
 
108
+ /**
109
+ * Decode an offline stream asynchronously (non-blocking).
110
+ * @param {OfflineStream} stream
111
+ * @returns {Promise<OfflineRecognizerResult>}
112
+ */
113
+ async decodeAsync(stream) {
114
+ const jsonStr =
115
+ await addon.decodeOfflineStreamAsync(this.handle, stream.handle);
116
+ return JSON.parse(jsonStr);
117
+ }
118
+
119
+ /**
120
+ * Get recognition result for a stream.
121
+ * @param {OfflineStream} stream
122
+ * @returns {OfflineRecognizerResult}
123
+ */
35
124
  getResult(stream) {
36
125
  const jsonStr = addon.getOfflineStreamResultAsJson(stream.handle);
37
-
38
126
  return JSON.parse(jsonStr);
39
127
  }
40
128
  }
@@ -42,4 +130,4 @@ class OfflineRecognizer {
42
130
  module.exports = {
43
131
  OfflineRecognizer,
44
132
  OfflineStream,
45
- }
133
+ };
@@ -1,6 +1,12 @@
1
+ /** @typedef {import('./types').OfflineSpeakerDiarizationConfig} OfflineSpeakerDiarizationConfig */
2
+ /** @typedef {import('./types').SpeakerDiarizationSegment} SpeakerDiarizationSegment */
3
+
1
4
  const addon = require('./addon.js');
2
5
 
3
6
  class OfflineSpeakerDiarization {
7
+ /**
8
+ * @param {OfflineSpeakerDiarizationConfig} config
9
+ */
4
10
  constructor(config) {
5
11
  this.handle = addon.createOfflineSpeakerDiarization(config);
6
12
  this.config = config;
@@ -9,23 +15,17 @@ class OfflineSpeakerDiarization {
9
15
  }
10
16
 
11
17
  /**
12
- * samples is a 1-d float32 array. Each element of the array should be
13
- * in the range [-1, 1].
14
- *
15
- * We assume its sample rate equals to this.sampleRate.
16
- *
17
- * Returns an array of object, where an object is
18
- *
19
- * {
20
- * "start": start_time_in_seconds,
21
- * "end": end_time_in_seconds,
22
- * "speaker": an_integer,
23
- * }
18
+ * @param {Float32Array} samples - 1-D float32 array in [-1, 1]
19
+ * @returns {SpeakerDiarizationSegment[]}
24
20
  */
25
21
  process(samples) {
26
22
  return addon.offlineSpeakerDiarizationProcess(this.handle, samples);
27
23
  }
28
24
 
25
+ /**
26
+ * Set clustering configuration.
27
+ * @param {{clustering: import('./types').FastClusteringConfig}} config
28
+ */
29
29
  setConfig(config) {
30
30
  addon.offlineSpeakerDiarizationSetConfig(this.handle, config);
31
31
  this.config.clustering = config.clustering;
@@ -34,4 +34,4 @@ class OfflineSpeakerDiarization {
34
34
 
35
35
  module.exports = {
36
36
  OfflineSpeakerDiarization,
37
- }
37
+ }
@@ -1,6 +1,13 @@
1
+ /** @typedef {import('./types').OfflineSpeechDenoiserConfig} OfflineSpeechDenoiserConfig */
2
+ /** @typedef {import('./types').GeneratedAudio} GeneratedAudio */
3
+ /** @typedef {import('./types').AudioProcessRequest} AudioProcessRequest */
4
+
1
5
  const addon = require('./addon.js');
2
6
 
3
7
  class OfflineSpeechDenoiser {
8
+ /**
9
+ * @param {OfflineSpeechDenoiserConfig} config
10
+ */
4
11
  constructor(config) {
5
12
  this.handle = addon.createOfflineSpeechDenoiser(config);
6
13
  this.config = config;
@@ -9,14 +16,10 @@ class OfflineSpeechDenoiser {
9
16
  addon.offlineSpeechDenoiserGetSampleRateWrapper(this.handle);
10
17
  }
11
18
 
12
- /*
13
- obj is
14
- {samples: samples, sampleRate: sampleRate, enableExternalBuffer: true}
15
-
16
- samples is a float32 array containing samples in the range [-1, 1]
17
- sampleRate is a number
18
-
19
- return an object {samples: Float32Array, sampleRate: <a number>}
19
+ /**
20
+ * Run denoiser synchronously.
21
+ * @param {AudioProcessRequest} obj - { samples: Float32Array, sampleRate: number, enableExternalBuffer?: boolean }
22
+ * @returns {GeneratedAudio}
20
23
  */
21
24
  run(obj) {
22
25
  return addon.offlineSpeechDenoiserRunWrapper(this.handle, obj);
@@ -25,4 +28,4 @@ class OfflineSpeechDenoiser {
25
28
 
26
29
  module.exports = {
27
30
  OfflineSpeechDenoiser,
28
- }
31
+ }
@@ -1,6 +1,13 @@
1
+ /** @typedef {import('./types').OfflineTtsConfig} OfflineTtsConfig */
2
+ /** @typedef {import('./types').TtsRequest} TtsRequest */
3
+ /** @typedef {import('./types').GeneratedAudio} GeneratedAudio */
4
+
1
5
  const addon = require('./addon.js');
2
6
 
3
7
  class OfflineTts {
8
+ /**
9
+ * @param {OfflineTtsConfig} config
10
+ */
4
11
  constructor(config) {
5
12
  this.handle = addon.createOfflineTts(config);
6
13
  this.config = config;
@@ -9,11 +16,10 @@ class OfflineTts {
9
16
  this.sampleRate = addon.getOfflineTtsSampleRate(this.handle);
10
17
  }
11
18
 
12
- /*
13
- input obj: {text: "xxxx", sid: 0, speed: 1.0}
14
- where text is a string, sid is a int32, speed is a float
15
-
16
- return an object {samples: Float32Array, sampleRate: <a number>}
19
+ /**
20
+ * Generate audio synchronously.
21
+ * @param {TtsRequest} obj
22
+ * @returns {GeneratedAudio}
17
23
  */
18
24
  generate(obj) {
19
25
  return addon.offlineTtsGenerate(this.handle, obj);
@@ -22,4 +28,4 @@ class OfflineTts {
22
28
 
23
29
  module.exports = {
24
30
  OfflineTts,
25
- }
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sherpa-onnx-node",
3
- "version": "1.12.21",
3
+ "version": "1.12.23",
4
4
  "description": "Speech-to-text, text-to-speech, speaker diarization, and speech enhancement using Next-gen Kaldi without internet connection",
5
5
  "main": "sherpa-onnx.js",
6
6
  "scripts": {
@@ -57,11 +57,11 @@
57
57
  },
58
58
  "homepage": "https://github.com/csukuangfj/sherpa-onnx#readme",
59
59
  "optionalDependencies": {
60
- "sherpa-onnx-darwin-arm64": "^1.12.21",
61
- "sherpa-onnx-darwin-x64": "^1.12.21",
62
- "sherpa-onnx-linux-x64": "^1.12.21",
63
- "sherpa-onnx-linux-arm64": "^1.12.21",
64
- "sherpa-onnx-win-x64": "^1.12.21",
65
- "sherpa-onnx-win-ia32": "^1.12.21"
60
+ "sherpa-onnx-darwin-arm64": "^1.12.23",
61
+ "sherpa-onnx-darwin-x64": "^1.12.23",
62
+ "sherpa-onnx-linux-x64": "^1.12.23",
63
+ "sherpa-onnx-linux-arm64": "^1.12.23",
64
+ "sherpa-onnx-win-x64": "^1.12.23",
65
+ "sherpa-onnx-win-ia32": "^1.12.23"
66
66
  }
67
67
  }
package/punctuation.js CHANGED
@@ -1,20 +1,36 @@
1
+ /** @typedef {import('./types').OfflinePunctuationHandle} OfflinePunctuationHandle */
2
+ /** @typedef {import('./types').OfflinePunctuationConfig} OfflinePunctuationConfig */
3
+ /** @typedef {import('./types').OnlinePunctuationConfig} OnlinePunctuationConfig */
4
+
1
5
  const addon = require('./addon.js');
2
6
 
3
7
  class OfflinePunctuation {
8
+ /**
9
+ * @param {OfflinePunctuationConfig} config
10
+ */
4
11
  constructor(config) {
5
12
  this.handle = addon.createOfflinePunctuation(config);
6
13
  this.config = config;
7
14
  }
15
+ /**
16
+ * Add punctuation to `text` and return the punctuated text.
17
+ * @param {string} text
18
+ * @returns {string}
19
+ */
8
20
  addPunct(text) {
9
21
  return addon.offlinePunctuationAddPunct(this.handle, text);
10
22
  }
11
23
  }
12
24
 
13
25
  class OnlinePunctuation {
26
+ /**
27
+ * @param {OnlinePunctuationConfig} config
28
+ */
14
29
  constructor(config) {
15
30
  this.handle = addon.createOnlinePunctuation(config);
16
31
  this.config = config;
17
32
  }
33
+ /** @param {string} text @returns {string} */
18
34
  addPunct(text) {
19
35
  return addon.onlinePunctuationAddPunct(this.handle, text);
20
36
  }
@@ -23,4 +39,4 @@ class OnlinePunctuation {
23
39
  module.exports = {
24
40
  OfflinePunctuation,
25
41
  OnlinePunctuation,
26
- }
42
+ }
package/sherpa-onnx.js CHANGED
@@ -1,3 +1,7 @@
1
+ /** @typedef {import('./types').WaveObject} WaveObject */
2
+ /** @typedef {import('./types').OnlineRecognizerResult} OnlineRecognizerResult */
3
+ /** @typedef {import('./types').OfflineRecognizerResult} OfflineRecognizerResult */
4
+
1
5
  const addon = require('./addon.js')
2
6
  const streaming_asr = require('./streaming-asr.js');
3
7
  const non_streaming_asr = require('./non-streaming-asr.js');
@@ -1,29 +1,58 @@
1
+ /** @typedef {import('./types').SpeakerEmbeddingEntry} SpeakerEmbeddingEntry */
2
+ /** @typedef {import('./types').SpeakerEmbeddingManagerSearchObj} SpeakerEmbeddingManagerSearchObj */
3
+ /** @typedef {import('./types').SpeakerEmbeddingManagerVerifyObj} SpeakerEmbeddingManagerVerifyObj */
4
+ /** @typedef {import('./types').SpeakerEmbeddingExtractorConfig} SpeakerEmbeddingExtractorConfig */
5
+ /** @typedef {import('./streaming-asr').OnlineStream} OnlineStream */
6
+
1
7
  const addon = require('./addon.js');
2
8
  const streaming_asr = require('./streaming-asr.js');
3
9
 
10
+ /**
11
+ * SpeakerEmbeddingExtractor wraps native speaker embedding extractor.
12
+ */
4
13
  class SpeakerEmbeddingExtractor {
14
+ /**
15
+ * @param {SpeakerEmbeddingExtractorConfig} config
16
+ */
5
17
  constructor(config) {
6
18
  this.handle = addon.createSpeakerEmbeddingExtractor(config);
7
19
  this.config = config;
8
20
  this.dim = addon.speakerEmbeddingExtractorDim(this.handle);
9
21
  }
10
22
 
23
+ /**
24
+ * @returns {OnlineStream}
25
+ */
11
26
  createStream() {
12
27
  return new streaming_asr.OnlineStream(
13
28
  addon.speakerEmbeddingExtractorCreateStream(this.handle));
14
29
  }
15
30
 
31
+ /**
32
+ * @param {OnlineStream} stream
33
+ * @returns {boolean}
34
+ */
16
35
  isReady(stream) {
17
36
  return addon.speakerEmbeddingExtractorIsReady(this.handle, stream.handle);
18
37
  }
19
38
 
20
- // return a float32 array
39
+ /**
40
+ * Compute embedding and return a Float32Array
41
+ * @param {OnlineStream} stream
42
+ * @param {boolean} [enableExternalBuffer=true]
43
+ * @returns {Float32Array}
44
+ */
21
45
  compute(stream, enableExternalBuffer = true) {
22
46
  return addon.speakerEmbeddingExtractorComputeEmbedding(
23
47
  this.handle, stream.handle, enableExternalBuffer);
24
48
  }
25
49
  }
26
50
 
51
+ /**
52
+ * Flattens an array of Float32Arrays into a single Float32Array.
53
+ * @param {Float32Array[]} arrayList
54
+ * @returns {Float32Array}
55
+ */
27
56
  function flatten(arrayList) {
28
57
  let n = 0;
29
58
  for (let i = 0; i < arrayList.length; ++i) {
@@ -39,22 +68,29 @@ function flatten(arrayList) {
39
68
  return ans;
40
69
  }
41
70
 
71
+ /**
72
+ * Manager for speaker embeddings.
73
+ */
42
74
  class SpeakerEmbeddingManager {
75
+ /**
76
+ * @param {number} dim - The embedding dimension
77
+ */
43
78
  constructor(dim) {
44
79
  this.handle = addon.createSpeakerEmbeddingManager(dim);
45
80
  this.dim = dim;
46
81
  }
47
82
 
48
- /*
49
- obj = {name: "xxx", v: a-float32-array}
83
+ /**
84
+ * @param {SpeakerEmbeddingEntry} obj
85
+ * @returns {boolean}
50
86
  */
51
87
  add(obj) {
52
88
  return addon.speakerEmbeddingManagerAdd(this.handle, obj);
53
89
  }
54
90
 
55
- /*
56
- * obj =
57
- * {name: "xxx", v: [float32_array1, float32_array2, ..., float32_arrayn]
91
+ /**
92
+ * @param {{name:string, v: Float32Array[]}} obj
93
+ * @returns {boolean}
58
94
  */
59
95
  addMulti(obj) {
60
96
  const c = {
@@ -65,32 +101,44 @@ class SpeakerEmbeddingManager {
65
101
  return addon.speakerEmbeddingManagerAddListFlattened(this.handle, c);
66
102
  }
67
103
 
104
+ /**
105
+ * @param {string} name
106
+ * @returns {boolean}
107
+ */
68
108
  remove(name) {
69
109
  return addon.speakerEmbeddingManagerRemove(this.handle, name);
70
110
  }
71
111
 
72
- /*
73
- * obj = {v: a-float32-array, threshold: a-float }
112
+ /**
113
+ * @param {SpeakerEmbeddingManagerSearchObj} obj
114
+ * @returns {string}
74
115
  */
75
116
  search(obj) {
76
117
  return addon.speakerEmbeddingManagerSearch(this.handle, obj);
77
118
  }
78
119
 
79
- /*
80
- * obj = {name: 'xxx', v: a-float32-array, threshold: a-float }
120
+ /**
121
+ * @param {SpeakerEmbeddingManagerVerifyObj} obj
122
+ * @returns {boolean}
81
123
  */
82
124
  verify(obj) {
83
125
  return addon.speakerEmbeddingManagerVerify(this.handle, obj);
84
126
  }
85
127
 
128
+ /**
129
+ * @param {string} name
130
+ * @returns {boolean}
131
+ */
86
132
  contains(name) {
87
133
  return addon.speakerEmbeddingManagerContains(this.handle, name);
88
134
  }
89
135
 
136
+ /** @returns {number} */
90
137
  getNumSpeakers() {
91
138
  return addon.speakerEmbeddingManagerNumSpeakers(this.handle);
92
139
  }
93
140
 
141
+ /** @returns {string[]} */
94
142
  getAllSpeakerNames() {
95
143
  return addon.speakerEmbeddingManagerGetAllSpeakers(this.handle);
96
144
  }
@@ -1,24 +1,31 @@
1
+ /** @typedef {import('./types').SpokenLanguageIdentificationConfig} SpokenLanguageIdentificationConfig */
2
+ /** @typedef {import('./non-streaming-asr').OfflineStream} OfflineStream */
3
+
1
4
  const addon = require('./addon.js');
2
5
  const non_streaming_asr = require('./non-streaming-asr.js');
3
6
 
4
7
  class SpokenLanguageIdentification {
8
+ /**
9
+ * @param {SpokenLanguageIdentificationConfig} config
10
+ */
5
11
  constructor(config) {
6
12
  this.handle = addon.createSpokenLanguageIdentification(config);
7
13
  this.config = config;
8
14
  }
9
15
 
16
+ /**
17
+ * @returns {OfflineStream}
18
+ */
10
19
  createStream() {
11
20
  return new non_streaming_asr.OfflineStream(
12
21
  addon.createSpokenLanguageIdentificationOfflineStream(this.handle));
13
22
  }
14
23
 
15
- // return a string containing the language code (2 characters),
16
- // e.g., en, de, fr, es, zh
17
- // en -> English
18
- // de -> German
19
- // fr -> French
20
- // es -> Spanish
21
- // zh -> Chinese
24
+ /**
25
+ * Return a 2-letter language code, e.g. 'en', 'de', 'fr', 'es', 'zh'
26
+ * @param {OfflineStream} stream
27
+ * @returns {string}
28
+ */
22
29
  compute(stream) {
23
30
  return addon.spokenLanguageIdentificationCompute(
24
31
  this.handle, stream.handle);
@@ -27,4 +34,4 @@ class SpokenLanguageIdentification {
27
34
 
28
35
  module.exports = {
29
36
  SpokenLanguageIdentification,
30
- }
37
+ }