-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add audio tagging APIs for node-addon-api (#875)
- Loading branch information
1 parent
388e6a9
commit d19f50b
Showing
12 changed files
with
520 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2024 Xiaomi Corporation | ||
const sherpa_onnx = require('sherpa-onnx-node'); | ||
|
||
// Please download models files from | ||
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/audio-tagging-models | ||
function createAudioTagging() { | ||
const config = { | ||
model: { | ||
ced: './sherpa-onnx-ced-mini-audio-tagging-2024-04-19/model.int8.onnx', | ||
numThreads: 1, | ||
debug: true, | ||
}, | ||
labels: | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/class_labels_indices.csv', | ||
topK: 5, | ||
}; | ||
return new sherpa_onnx.AudioTagging(config); | ||
} | ||
|
||
const at = createAudioTagging(); | ||
|
||
const testWaves = [ | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/test_wavs/1.wav', | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/test_wavs/2.wav', | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/test_wavs/3.wav', | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/test_wavs/4.wav', | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/test_wavs/5.wav', | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/test_wavs/6.wav', | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/test_wavs/7.wav', | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/test_wavs/8.wav', | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/test_wavs/9.wav', | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/test_wavs/10.wav', | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/test_wavs/11.wav', | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/test_wavs/12.wav', | ||
'./sherpa-onnx-ced-mini-audio-tagging-2024-04-19/test_wavs/13.wav', | ||
]; | ||
|
||
console.log('------'); | ||
|
||
for (let filename of testWaves) { | ||
const start = performance.now(); | ||
const stream = at.createStream(); | ||
const wave = sherpa_onnx.readWave(filename); | ||
stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples}); | ||
const events = at.compute(stream); | ||
const stop = performance.now(); | ||
|
||
const elapsed_seconds = (stop - start) / 1000; | ||
const duration = wave.samples.length / wave.sampleRate; | ||
const real_time_factor = elapsed_seconds / duration; | ||
|
||
console.log('input file:', filename); | ||
console.log('Probability\t\tName'); | ||
for (let e of events) { | ||
console.log(`${e.prob.toFixed(3)}\t\t\t${e.name}`); | ||
} | ||
console.log('Wave duration', duration.toFixed(3), 'secodns') | ||
console.log('Elapsed', elapsed_seconds.toFixed(3), 'secodns') | ||
console.log( | ||
`RTF = ${elapsed_seconds.toFixed(3)}/${duration.toFixed(3)} =`, | ||
real_time_factor.toFixed(3)) | ||
console.log('------'); | ||
} |
Oops, something went wrong.