@digipair/skill-web-voice-activity-detection 0.94.0-0 → 0.94.0-3

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/index.cjs.js ADDED
@@ -0,0 +1,110 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var engine = require('@digipair/engine');
6
+
7
+ function _extends() {
8
+ _extends = Object.assign || function assign(target) {
9
+ for(var i = 1; i < arguments.length; i++){
10
+ var source = arguments[i];
11
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
12
+ }
13
+ return target;
14
+ };
15
+ return _extends.apply(this, arguments);
16
+ }
17
+
18
+ // add a script tag to the document
19
+ async function addScript(src) {
20
+ const script = document.createElement('script');
21
+ script.src = src;
22
+ script.async = false;
23
+ document.body.appendChild(script);
24
+ return new Promise((resolve)=>{
25
+ script.onload = resolve;
26
+ });
27
+ }
28
+ let VADService = class VADService {
29
+ async listen(params, _pinsSettingsList, context) {
30
+ const globalInstance = typeof window === 'undefined' ? global : window;
31
+ const config = globalInstance.__DIGIPAIR_CONFIG__;
32
+ const { stream = await navigator.mediaDevices.getUserMedia({
33
+ audio: {
34
+ channelCount: 1,
35
+ echoCancellation: true,
36
+ autoGainControl: true,
37
+ noiseSuppression: true
38
+ }
39
+ }), onFrameProcessed = [], onVADMisfire = [], onSpeechStart = [], onSpeechEnd = [], model = 'legacy', additionalAudioConstraints = {}, baseAssetPath = `${config.BASE_URL}/@ricky0123/vad-web@0.0.22/dist/`, onnxWASMBasePath = `${config.BASE_URL}/onnxruntime-web@1.18.0/dist/`, submitUserSpeechOnPause = false, positiveSpeechThreshold = 0.5, negativeSpeechThreshold = 0.35, preSpeechPadFrames = 1, redemptionFrames = 8, frameSamples = 1536, minSpeechFrames = 3 } = params;
40
+ if (!document.querySelector(`script[src="${onnxWASMBasePath}ort.js"]`)) {
41
+ await addScript(`${onnxWASMBasePath}ort.js`);
42
+ }
43
+ if (!document.querySelector(`script[src="${baseAssetPath}bundle.min.js"]`)) {
44
+ await addScript(`${baseAssetPath}bundle.min.js`);
45
+ }
46
+ const { MicVAD, utils } = window['vad'];
47
+ const vad = await MicVAD.new({
48
+ stream,
49
+ onFrameProcessed: (probabilities, frame)=>{
50
+ engine.executePinsList(onFrameProcessed, _extends({}, context, {
51
+ probabilities,
52
+ frame,
53
+ vad
54
+ }), `${context.__PATH__}.onFrameProcessed`);
55
+ },
56
+ onVADMisfire: ()=>{
57
+ engine.executePinsList(onVADMisfire, _extends({}, context, {
58
+ vad
59
+ }), `${context.__PATH__}.onVADMisfire`);
60
+ },
61
+ onSpeechStart: ()=>{
62
+ engine.executePinsList(onSpeechStart, _extends({}, context, {
63
+ vad
64
+ }), `${context.__PATH__}.onSpeechStart`);
65
+ },
66
+ onSpeechEnd: (buffer)=>{
67
+ const wavBuffer = utils.encodeWAV(buffer);
68
+ const base64 = utils.arrayBufferToBase64(wavBuffer);
69
+ const audio = `data:audio/wav;base64,${base64}`;
70
+ engine.executePinsList(onSpeechEnd, _extends({}, context, {
71
+ audio,
72
+ vad
73
+ }), `${context.__PATH__}.onSpeechEnd`);
74
+ },
75
+ additionalAudioConstraints,
76
+ positiveSpeechThreshold,
77
+ negativeSpeechThreshold,
78
+ redemptionFrames,
79
+ frameSamples,
80
+ preSpeechPadFrames,
81
+ minSpeechFrames,
82
+ model,
83
+ baseAssetPath,
84
+ onnxWASMBasePath,
85
+ submitUserSpeechOnPause
86
+ });
87
+ return vad;
88
+ }
89
+ async start(params, _pinsSettingsList, context) {
90
+ const { vad = context.vad } = params;
91
+ return vad.start();
92
+ }
93
+ async pause(params, _pinsSettingsList, context) {
94
+ const { vad = context.vad } = params;
95
+ return vad.pause();
96
+ }
97
+ async destroy(params, _pinsSettingsList, context) {
98
+ const { vad = context.vad } = params;
99
+ return vad.destroy();
100
+ }
101
+ };
102
+ const listen = (params, pinsSettingsList, context)=>new VADService().listen(params, pinsSettingsList, context);
103
+ const start = (params, pinsSettingsList, context)=>new VADService().start(params, pinsSettingsList, context);
104
+ const pause = (params, pinsSettingsList, context)=>new VADService().pause(params, pinsSettingsList, context);
105
+ const destroy = (params, pinsSettingsList, context)=>new VADService().destroy(params, pinsSettingsList, context);
106
+
107
+ exports.destroy = destroy;
108
+ exports.listen = listen;
109
+ exports.pause = pause;
110
+ exports.start = start;
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './libs/skill-web-voice-activity-detection/src/index';