@untemps/vocal 2.0.0-beta.1 → 2.0.0-beta.11

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/CHANGELOG.md CHANGED
@@ -1,3 +1,84 @@
1
+ # [2.0.0-beta.11](https://github.com/untemps/vocal/compare/v2.0.0-beta.10...v2.0.0-beta.11) (2026-05-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Throw on invalid event type in addEventListener and removeEventListener ([#69](https://github.com/untemps/vocal/issues/69)) ([a474718](https://github.com/untemps/vocal/commit/a474718fc7f36e4828a5430cf7c19b851401189d))
7
+
8
+ # [2.0.0-beta.10](https://github.com/untemps/vocal/compare/v2.0.0-beta.9...v2.0.0-beta.10) (2026-05-16)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Remove internal end listener on cleanup ([#68](https://github.com/untemps/vocal/issues/68)) ([3179943](https://github.com/untemps/vocal/commit/31799433b054cca334d6159d8aae9e00c8971b6d))
14
+
15
+ # [2.0.0-beta.9](https://github.com/untemps/vocal/compare/v2.0.0-beta.8...v2.0.0-beta.9) (2026-05-16)
16
+
17
+ # [2.0.0-beta.8](https://github.com/untemps/vocal/compare/v2.0.0-beta.7...v2.0.0-beta.8) (2026-05-16)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * Return false from isSupported in non-browser environments ([#65](https://github.com/untemps/vocal/issues/65)) ([56f67cc](https://github.com/untemps/vocal/commit/56f67cc6cc9ff6288472d1461a71d3e0cbc128ed))
23
+
24
+ # [2.0.0-beta.7](https://github.com/untemps/vocal/compare/v2.0.0-beta.6...v2.0.0-beta.7) (2026-05-16)
25
+
26
+
27
+ ### Bug Fixes
28
+
29
+ * Use resultIndex to select current result in continuous mode ([#64](https://github.com/untemps/vocal/issues/64)) ([62d61c4](https://github.com/untemps/vocal/commit/62d61c41ec7713cb01d578568b462734324e722a))
30
+
31
+ # [2.0.0-beta.6](https://github.com/untemps/vocal/compare/v2.0.0-beta.5...v2.0.0-beta.6) (2026-05-16)
32
+
33
+
34
+ ### chore
35
+
36
+ * Add type module and rename CJS dist to index.cjs ([#45](https://github.com/untemps/vocal/issues/45)) ([e9923af](https://github.com/untemps/vocal/commit/e9923af7032fe48fc0b214bb77e3d6708a4b1adb))
37
+
38
+
39
+ ### BREAKING CHANGES
40
+
41
+ * "main" field: dist/index.js → dist/index.cjs. Consumers using the main field directly (not via the exports map) must update their import path.
42
+ Consumers using the exports map (require/import conditions) are not affected.
43
+
44
+ # [2.0.0-beta.5](https://github.com/untemps/vocal/compare/v2.0.0-beta.4...v2.0.0-beta.5) (2026-05-16)
45
+
46
+
47
+ * refactor!: Select best RESULT transcript by confidence ([#44](https://github.com/untemps/vocal/issues/44)) ([4713366](https://github.com/untemps/vocal/commit/471336641a156623a17b6f7e0602658a3086381d))
48
+
49
+
50
+ ### BREAKING CHANGES
51
+
52
+ * The RESULT callback signature changes from (event, transcript: string, alternatives: string[]) to (event, bestAlternative: string, alternatives: string[]) where bestAlternative is the alternative with the highest confidence score instead of the first in the array.
53
+ Migration: no change needed if confidence ordering matches array order (standard browser behavior); replace transcript with bestAlternative if using the parameter name.
54
+
55
+ # [2.0.0-beta.4](https://github.com/untemps/vocal/compare/v2.0.0-beta.3...v2.0.0-beta.4) (2026-05-16)
56
+
57
+
58
+ ### Features
59
+
60
+ * start() rejects on error instead of always resolving ([#43](https://github.com/untemps/vocal/issues/43)) ([4414f11](https://github.com/untemps/vocal/commit/4414f11608e795b94845d06e6be53e8e5a76e022))
61
+
62
+
63
+ ### BREAKING CHANGES
64
+
65
+ * start(): no longer resolves when the microphone stream fails. Callers who did not handle rejections will receive an UnhandledPromiseRejection.
66
+ Migration: wrap await vocal.start() in try/catch, or use .catch().
67
+
68
+ # [2.0.0-beta.3](https://github.com/untemps/vocal/compare/v2.0.0-beta.2...v2.0.0-beta.3) (2026-05-15)
69
+
70
+
71
+ ### Features
72
+
73
+ * Expose AbortSignal support in start() ([#42](https://github.com/untemps/vocal/issues/42)) ([a7f638b](https://github.com/untemps/vocal/commit/a7f638b541347a4377bce1f43a47aa5290ea2852))
74
+
75
+ # [2.0.0-beta.2](https://github.com/untemps/vocal/compare/v2.0.0-beta.1...v2.0.0-beta.2) (2026-05-15)
76
+
77
+
78
+ ### Features
79
+
80
+ * Add isRecording getter to track recognition state ([#41](https://github.com/untemps/vocal/issues/41)) ([7abcc56](https://github.com/untemps/vocal/commit/7abcc566f40aa95af88078d2a7632ef8633cad5a))
81
+
1
82
  # [2.0.0-beta.1](https://github.com/untemps/vocal/compare/v1.3.4-beta.1...v2.0.0-beta.1) (2026-05-15)
2
83
 
3
84
 
package/README.md CHANGED
@@ -33,11 +33,15 @@ const vocal = new Vocal(options)
33
33
  // Subscribe to Vocal instance events (see below for all available events)
34
34
  vocal.addEventListener('speechstart', (event) => console.log('Vocal starts recording'))
35
35
  vocal.addEventListener('speechend', (event) => console.log('Vocal stops recording'))
36
- vocal.addEventListener('result', (event, transcript, alternatives) => console.log('Vocal catches a result:', transcript, alternatives))
36
+ vocal.addEventListener('result', (event, bestAlternative, alternatives) => console.log('Vocal catches a result:', bestAlternative, alternatives))
37
37
  vocal.addEventListener('error', (error) => { throw error })
38
38
 
39
- // Start recording
40
- vocal.start()
39
+ // Start recording — rejects on error
40
+ try {
41
+ await vocal.start()
42
+ } catch (error) {
43
+ // handle error
44
+ }
41
45
 
42
46
  // Stop/Pause recording
43
47
  vocal.stop()
@@ -73,9 +77,34 @@ Please refer to [this section](https://developer.mozilla.org/en-US/docs/Web/API/
73
77
  | end | Fired when the recognition service has disconnected |
74
78
  | error | Fired when a recognition error occurs |
75
79
  | nomatch | Fired when the recognition service returns a final result with no significant recognition |
76
- | result | Fired when the recognition service returns a result — callback receives `(event, transcript: string, alternatives: string[])` where `transcript === alternatives[0]` |
80
+ | result | Fired when the recognition service returns a result — callback receives `(event, bestAlternative: string, alternatives: string[])` where `bestAlternative` is the alternative with the highest confidence |
77
81
  | soundend | Fired when any sound — recognisable or not — has stopped being detected |
78
82
  | soundstart | Fired when any sound — recognisable or not — has been detected |
79
83
  | speechend | Fired when speech recognized by the recognition service has stopped being detected |
80
84
  | speechstart | Fired when sound recognized by the recognition service as speech has been detected |
81
- | start | fired when the recognition service has begun listening to incoming audio |
85
+ | start | fired when the recognition service has begun listening to incoming audio |
86
+
87
+ ## Getters
88
+
89
+ | Getter | Type | Description |
90
+ | ----------- | ------------------------- | -------------------------------------------------------------------------------------------------------------------- |
91
+ | isSupported | boolean | Whether the current environment supports the SpeechRecognition Web API (static) |
92
+ | instance | SpeechRecognition \| null | The underlying SpeechRecognition instance |
93
+ | isRecording | boolean | Whether recognition is currently active — `true` after `start()`, `false` after `stop()`, `abort()`, or `end` event |
94
+
95
+ ## Methods
96
+
97
+ ### `start({ signal? })`
98
+
99
+ | Parameter | Type | Default | Description |
100
+ | --------- | ------------- | ----------- | ----------------------------------------------------------------------------- |
101
+ | signal | AbortSignal | `undefined` | Cancels the in-flight microphone permission request when the signal is aborted |
102
+
103
+ ```js
104
+ const controller = new AbortController()
105
+ vocal.start({ signal: controller.signal })
106
+
107
+ // Cancel the permission request at any later point
108
+ controller.abort()
109
+ ```
110
+
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@untemps/user-permissions-utils`);var t=class t{static defaultOptions={grammars:null,lang:`en-US`,continuous:!1,interimResults:!1,maxAlternatives:1};static eventTypes={AUDIO_END:`audioend`,AUDIO_START:`audiostart`,END:`end`,ERROR:`error`,NO_MATCH:`nomatch`,RESULT:`result`,SOUND_END:`soundend`,SOUND_START:`soundstart`,SPEECH_END:`speechend`,SPEECH_START:`speechstart`,START:`start`};static get isSupported(){return!!t._resolveSpeechRecognition()&&!!(0,e.isNavigatorPermissionsSupported)()&&!!(0,e.isNavigatorMediaDevicesSupported)()}static set isSupported(e){throw Error(`You cannot set isSupported directly.`)}_instance=null;_listeners=null;_isRecording=!1;_onEnd=()=>{this._isRecording=!1};constructor(e){let n=t._resolveSpeechRecognition();if(!n)throw new DOMException(`SpeechRecognition not supported`,`NOT_SUPPORTED_ERR`);this._instance=new n,this._listeners={};let{grammars:r,...i}={...t.defaultOptions,...e??{}},a=this._instance;if(Object.assign(a,i),r)a.grammars=r;else{let e=t._resolveSpeechGrammarList();a.grammars=e?new e:null}this._instance.addEventListener(`end`,this._onEnd)}get instance(){return this._instance}set instance(e){throw Error(`You cannot set instance directly.`)}get isRecording(){return this._isRecording}set isRecording(e){throw Error(`You cannot set isRecording directly.`)}async start({signal:t}={}){if(this._instance)try{if(!await(0,e.getUserMediaStream)(`microphone`,{audio:!0},{signal:t}))throw Error(`Unable to retrieve the stream from media device`);this._instance.start(),this._isRecording=!0}catch(e){if(e instanceof Error&&e.name===`AbortError`)return this;throw e}return this}stop(){return this._instance&&(this._instance.stop(),this._isRecording=!1),this}abort(){return this._instance&&(this._instance.abort(),this._isRecording=!1),this}addEventListener(e,n){if(!this._includesEventType(e))throw Error(this._unknownEventTypeMessage(e));if(this._instance&&this._listeners){this._listeners[e]&&this.removeEventListener(e);let r=r=>{let i=[];if(e===t.eventTypes.RESULT){let e=r;if(e.results?.length>0&&e.resultIndex<e.results.length){let t=Array.from(e.results[e.resultIndex]),n=t.reduce((e,t)=>(t.confidence??0)>(e.confidence??0)?t:e);i.push(n.transcript,t.map(e=>e.transcript))}}n.apply(this,[r,...i])};this._instance.addEventListener(e,r),this._listeners[e]=r}return this}removeEventListener(e){if(!this._includesEventType(e))throw Error(this._unknownEventTypeMessage(e));if(this._instance&&this._listeners){let t=this._listeners[e];this._instance.removeEventListener(e,t),delete this._listeners[e]}return this}cleanup(){return this.stop(),Object.keys(this._listeners).forEach(e=>this.removeEventListener(e)),this._instance?.removeEventListener(`end`,this._onEnd),this._instance=null,this}_includesEventType(e){return Object.values(t.eventTypes).includes(e)}_unknownEventTypeMessage(e){return`Unknown event type "${e}". Valid types are: ${Object.values(t.eventTypes).join(`, `)}.`}static _resolveSpeechRecognition(){if(!(typeof window>`u`))return window.SpeechRecognition??window.webkitSpeechRecognition??window.mozSpeechRecognition??window.msSpeechRecognition}static _resolveSpeechGrammarList(){return window.SpeechGrammarList??window.webkitSpeechGrammarList??window.mozSpeechGrammarList??window.msSpeechGrammarList}};exports.Vocal=t;
2
+ //# sourceMappingURL=index.cjs.map
package/dist/index.es.js CHANGED
@@ -29,6 +29,10 @@ var r = class r {
29
29
  }
30
30
  _instance = null;
31
31
  _listeners = null;
32
+ _isRecording = !1;
33
+ _onEnd = () => {
34
+ this._isRecording = !1;
35
+ };
32
36
  constructor(e) {
33
37
  let t = r._resolveSpeechRecognition();
34
38
  if (!t) throw new DOMException("SpeechRecognition not supported", "NOT_SUPPORTED_ERR");
@@ -42,6 +46,7 @@ var r = class r {
42
46
  let e = r._resolveSpeechGrammarList();
43
47
  a.grammars = e ? new e() : null;
44
48
  }
49
+ this._instance.addEventListener("end", this._onEnd);
45
50
  }
46
51
  get instance() {
47
52
  return this._instance;
@@ -49,32 +54,39 @@ var r = class r {
49
54
  set instance(e) {
50
55
  throw Error("You cannot set instance directly.");
51
56
  }
52
- async start() {
57
+ get isRecording() {
58
+ return this._isRecording;
59
+ }
60
+ set isRecording(e) {
61
+ throw Error("You cannot set isRecording directly.");
62
+ }
63
+ async start({ signal: t } = {}) {
53
64
  if (this._instance) try {
54
- if (!await e("microphone", { audio: !0 })) throw Error("Unable to retrieve the stream from media device");
55
- this._instance.start();
65
+ if (!await e("microphone", { audio: !0 }, { signal: t })) throw Error("Unable to retrieve the stream from media device");
66
+ this._instance.start(), this._isRecording = !0;
56
67
  } catch (e) {
57
- let t = this._listeners?.error;
58
- t && t(e);
68
+ if (e instanceof Error && e.name === "AbortError") return this;
69
+ throw e;
59
70
  }
60
71
  return this;
61
72
  }
62
73
  stop() {
63
- return this._instance && this._instance.stop(), this;
74
+ return this._instance && (this._instance.stop(), this._isRecording = !1), this;
64
75
  }
65
76
  abort() {
66
- return this._instance && this._instance.abort(), this;
77
+ return this._instance && (this._instance.abort(), this._isRecording = !1), this;
67
78
  }
68
79
  addEventListener(e, t) {
69
- if (this._instance && this._listeners && this._includesEventType(e)) {
80
+ if (!this._includesEventType(e)) throw Error(this._unknownEventTypeMessage(e));
81
+ if (this._instance && this._listeners) {
70
82
  this._listeners[e] && this.removeEventListener(e);
71
83
  let n = (n) => {
72
84
  let i = [];
73
85
  if (e === r.eventTypes.RESULT) {
74
86
  let e = n;
75
- if (e.results?.length > 0) {
76
- let t = Array.from(e.results[0], (e) => e.transcript);
77
- i.push(t[0], t);
87
+ if (e.results?.length > 0 && e.resultIndex < e.results.length) {
88
+ let t = Array.from(e.results[e.resultIndex]), n = t.reduce((e, t) => (t.confidence ?? 0) > (e.confidence ?? 0) ? t : e);
89
+ i.push(n.transcript, t.map((e) => e.transcript));
78
90
  }
79
91
  }
80
92
  t.apply(this, [n, ...i]);
@@ -84,6 +96,7 @@ var r = class r {
84
96
  return this;
85
97
  }
86
98
  removeEventListener(e) {
99
+ if (!this._includesEventType(e)) throw Error(this._unknownEventTypeMessage(e));
87
100
  if (this._instance && this._listeners) {
88
101
  let t = this._listeners[e];
89
102
  this._instance.removeEventListener(e, t), delete this._listeners[e];
@@ -91,13 +104,16 @@ var r = class r {
91
104
  return this;
92
105
  }
93
106
  cleanup() {
94
- return this.stop(), Object.keys(this._listeners).forEach((e) => this.removeEventListener(e)), this._instance = null, this;
107
+ return this.stop(), Object.keys(this._listeners).forEach((e) => this.removeEventListener(e)), this._instance?.removeEventListener("end", this._onEnd), this._instance = null, this;
95
108
  }
96
109
  _includesEventType(e) {
97
110
  return Object.values(r.eventTypes).includes(e);
98
111
  }
112
+ _unknownEventTypeMessage(e) {
113
+ return `Unknown event type "${e}". Valid types are: ${Object.values(r.eventTypes).join(", ")}.`;
114
+ }
99
115
  static _resolveSpeechRecognition() {
100
- return window.SpeechRecognition ?? window.webkitSpeechRecognition ?? window.mozSpeechRecognition ?? window.msSpeechRecognition;
116
+ if (!(typeof window > "u")) return window.SpeechRecognition ?? window.webkitSpeechRecognition ?? window.mozSpeechRecognition ?? window.msSpeechRecognition;
101
117
  }
102
118
  static _resolveSpeechGrammarList() {
103
119
  return window.SpeechGrammarList ?? window.webkitSpeechGrammarList ?? window.mozSpeechGrammarList ?? window.msSpeechGrammarList;
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@untemps/user-permissions-utils`)):typeof define==`function`&&define.amd?define([`exports`,`@untemps/user-permissions-utils`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Vocal={},e.UserPermissionsUtils))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),e.Vocal=class e{static defaultOptions={grammars:null,lang:`en-US`,continuous:!1,interimResults:!1,maxAlternatives:1};static eventTypes={AUDIO_END:`audioend`,AUDIO_START:`audiostart`,END:`end`,ERROR:`error`,NO_MATCH:`nomatch`,RESULT:`result`,SOUND_END:`soundend`,SOUND_START:`soundstart`,SPEECH_END:`speechend`,SPEECH_START:`speechstart`,START:`start`};static get isSupported(){return!!e._resolveSpeechRecognition()&&!!(0,t.isNavigatorPermissionsSupported)()&&!!(0,t.isNavigatorMediaDevicesSupported)()}static set isSupported(e){throw Error(`You cannot set isSupported directly.`)}_instance=null;_listeners=null;constructor(t){let n=e._resolveSpeechRecognition();if(!n)throw new DOMException(`SpeechRecognition not supported`,`NOT_SUPPORTED_ERR`);this._instance=new n,this._listeners={};let{grammars:r,...i}={...e.defaultOptions,...t??{}},a=this._instance;if(Object.assign(a,i),r)a.grammars=r;else{let t=e._resolveSpeechGrammarList();a.grammars=t?new t:null}}get instance(){return this._instance}set instance(e){throw Error(`You cannot set instance directly.`)}async start(){if(this._instance)try{if(!await(0,t.getUserMediaStream)(`microphone`,{audio:!0}))throw Error(`Unable to retrieve the stream from media device`);this._instance.start()}catch(e){let t=this._listeners?.error;t&&t(e)}return this}stop(){return this._instance&&this._instance.stop(),this}abort(){return this._instance&&this._instance.abort(),this}addEventListener(t,n){if(this._instance&&this._listeners&&this._includesEventType(t)){this._listeners[t]&&this.removeEventListener(t);let r=r=>{let i=[];if(t===e.eventTypes.RESULT){let e=r;if(e.results?.length>0){let t=Array.from(e.results[0],e=>e.transcript);i.push(t[0],t)}}n.apply(this,[r,...i])};this._instance.addEventListener(t,r),this._listeners[t]=r}return this}removeEventListener(e){if(this._instance&&this._listeners){let t=this._listeners[e];this._instance.removeEventListener(e,t),delete this._listeners[e]}return this}cleanup(){return this.stop(),Object.keys(this._listeners).forEach(e=>this.removeEventListener(e)),this._instance=null,this}_includesEventType(t){return Object.values(e.eventTypes).includes(t)}static _resolveSpeechRecognition(){return window.SpeechRecognition??window.webkitSpeechRecognition??window.mozSpeechRecognition??window.msSpeechRecognition}static _resolveSpeechGrammarList(){return window.SpeechGrammarList??window.webkitSpeechGrammarList??window.mozSpeechGrammarList??window.msSpeechGrammarList}}});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@untemps/user-permissions-utils`)):typeof define==`function`&&define.amd?define([`exports`,`@untemps/user-permissions-utils`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Vocal={},e.UserPermissionsUtils))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),e.Vocal=class e{static defaultOptions={grammars:null,lang:`en-US`,continuous:!1,interimResults:!1,maxAlternatives:1};static eventTypes={AUDIO_END:`audioend`,AUDIO_START:`audiostart`,END:`end`,ERROR:`error`,NO_MATCH:`nomatch`,RESULT:`result`,SOUND_END:`soundend`,SOUND_START:`soundstart`,SPEECH_END:`speechend`,SPEECH_START:`speechstart`,START:`start`};static get isSupported(){return!!e._resolveSpeechRecognition()&&!!(0,t.isNavigatorPermissionsSupported)()&&!!(0,t.isNavigatorMediaDevicesSupported)()}static set isSupported(e){throw Error(`You cannot set isSupported directly.`)}_instance=null;_listeners=null;_isRecording=!1;_onEnd=()=>{this._isRecording=!1};constructor(t){let n=e._resolveSpeechRecognition();if(!n)throw new DOMException(`SpeechRecognition not supported`,`NOT_SUPPORTED_ERR`);this._instance=new n,this._listeners={};let{grammars:r,...i}={...e.defaultOptions,...t??{}},a=this._instance;if(Object.assign(a,i),r)a.grammars=r;else{let t=e._resolveSpeechGrammarList();a.grammars=t?new t:null}this._instance.addEventListener(`end`,this._onEnd)}get instance(){return this._instance}set instance(e){throw Error(`You cannot set instance directly.`)}get isRecording(){return this._isRecording}set isRecording(e){throw Error(`You cannot set isRecording directly.`)}async start({signal:e}={}){if(this._instance)try{if(!await(0,t.getUserMediaStream)(`microphone`,{audio:!0},{signal:e}))throw Error(`Unable to retrieve the stream from media device`);this._instance.start(),this._isRecording=!0}catch(e){if(e instanceof Error&&e.name===`AbortError`)return this;throw e}return this}stop(){return this._instance&&(this._instance.stop(),this._isRecording=!1),this}abort(){return this._instance&&(this._instance.abort(),this._isRecording=!1),this}addEventListener(t,n){if(!this._includesEventType(t))throw Error(this._unknownEventTypeMessage(t));if(this._instance&&this._listeners){this._listeners[t]&&this.removeEventListener(t);let r=r=>{let i=[];if(t===e.eventTypes.RESULT){let e=r;if(e.results?.length>0&&e.resultIndex<e.results.length){let t=Array.from(e.results[e.resultIndex]),n=t.reduce((e,t)=>(t.confidence??0)>(e.confidence??0)?t:e);i.push(n.transcript,t.map(e=>e.transcript))}}n.apply(this,[r,...i])};this._instance.addEventListener(t,r),this._listeners[t]=r}return this}removeEventListener(e){if(!this._includesEventType(e))throw Error(this._unknownEventTypeMessage(e));if(this._instance&&this._listeners){let t=this._listeners[e];this._instance.removeEventListener(e,t),delete this._listeners[e]}return this}cleanup(){return this.stop(),Object.keys(this._listeners).forEach(e=>this.removeEventListener(e)),this._instance?.removeEventListener(`end`,this._onEnd),this._instance=null,this}_includesEventType(t){return Object.values(e.eventTypes).includes(t)}_unknownEventTypeMessage(t){return`Unknown event type "${t}". Valid types are: ${Object.values(e.eventTypes).join(`, `)}.`}static _resolveSpeechRecognition(){if(!(typeof window>`u`))return window.SpeechRecognition??window.webkitSpeechRecognition??window.mozSpeechRecognition??window.msSpeechRecognition}static _resolveSpeechGrammarList(){return window.SpeechGrammarList??window.webkitSpeechGrammarList??window.mozSpeechGrammarList??window.msSpeechGrammarList}}});
2
2
  //# sourceMappingURL=index.umd.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@untemps/vocal",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.11",
4
4
  "description": "Class wrapped around the SpeechRecognition Web API",
5
5
  "repository": "git@github.com:untemps/vocal.git",
6
6
  "keywords": [
@@ -13,6 +13,7 @@
13
13
  "author": "Vincent Le Badezet <v.lebadezet@untemps.net>",
14
14
  "license": "MIT",
15
15
  "private": false,
16
+ "type": "module",
16
17
  "publishConfig": {
17
18
  "access": "public"
18
19
  },
@@ -20,20 +21,20 @@
20
21
  "node": ">=22"
21
22
  },
22
23
  "files": [
23
- "dist/index.js",
24
+ "dist/index.cjs",
24
25
  "dist/index.es.js",
25
26
  "dist/index.umd.js",
26
27
  "dist/index.d.ts",
27
28
  "CHANGELOG.md"
28
29
  ],
29
- "main": "dist/index.js",
30
+ "main": "dist/index.cjs",
30
31
  "module": "dist/index.es.js",
31
32
  "types": "dist/index.d.ts",
32
33
  "exports": {
33
34
  ".": {
34
35
  "types": "./dist/index.d.ts",
35
36
  "import": "./dist/index.es.js",
36
- "require": "./dist/index.js",
37
+ "require": "./dist/index.cjs",
37
38
  "default": "./dist/index.es.js"
38
39
  }
39
40
  },
@@ -91,7 +92,7 @@
91
92
  {
92
93
  "assets": [
93
94
  {
94
- "path": "dist/index.js",
95
+ "path": "dist/index.cjs",
95
96
  "label": "CJS distribution"
96
97
  },
97
98
  {
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@untemps/user-permissions-utils`);var t=class t{static defaultOptions={grammars:null,lang:`en-US`,continuous:!1,interimResults:!1,maxAlternatives:1};static eventTypes={AUDIO_END:`audioend`,AUDIO_START:`audiostart`,END:`end`,ERROR:`error`,NO_MATCH:`nomatch`,RESULT:`result`,SOUND_END:`soundend`,SOUND_START:`soundstart`,SPEECH_END:`speechend`,SPEECH_START:`speechstart`,START:`start`};static get isSupported(){return!!t._resolveSpeechRecognition()&&!!(0,e.isNavigatorPermissionsSupported)()&&!!(0,e.isNavigatorMediaDevicesSupported)()}static set isSupported(e){throw Error(`You cannot set isSupported directly.`)}_instance=null;_listeners=null;constructor(e){let n=t._resolveSpeechRecognition();if(!n)throw new DOMException(`SpeechRecognition not supported`,`NOT_SUPPORTED_ERR`);this._instance=new n,this._listeners={};let{grammars:r,...i}={...t.defaultOptions,...e??{}},a=this._instance;if(Object.assign(a,i),r)a.grammars=r;else{let e=t._resolveSpeechGrammarList();a.grammars=e?new e:null}}get instance(){return this._instance}set instance(e){throw Error(`You cannot set instance directly.`)}async start(){if(this._instance)try{if(!await(0,e.getUserMediaStream)(`microphone`,{audio:!0}))throw Error(`Unable to retrieve the stream from media device`);this._instance.start()}catch(e){let t=this._listeners?.error;t&&t(e)}return this}stop(){return this._instance&&this._instance.stop(),this}abort(){return this._instance&&this._instance.abort(),this}addEventListener(e,n){if(this._instance&&this._listeners&&this._includesEventType(e)){this._listeners[e]&&this.removeEventListener(e);let r=r=>{let i=[];if(e===t.eventTypes.RESULT){let e=r;if(e.results?.length>0){let t=Array.from(e.results[0],e=>e.transcript);i.push(t[0],t)}}n.apply(this,[r,...i])};this._instance.addEventListener(e,r),this._listeners[e]=r}return this}removeEventListener(e){if(this._instance&&this._listeners){let t=this._listeners[e];this._instance.removeEventListener(e,t),delete this._listeners[e]}return this}cleanup(){return this.stop(),Object.keys(this._listeners).forEach(e=>this.removeEventListener(e)),this._instance=null,this}_includesEventType(e){return Object.values(t.eventTypes).includes(e)}static _resolveSpeechRecognition(){return window.SpeechRecognition??window.webkitSpeechRecognition??window.mozSpeechRecognition??window.msSpeechRecognition}static _resolveSpeechGrammarList(){return window.SpeechGrammarList??window.webkitSpeechGrammarList??window.mozSpeechGrammarList??window.msSpeechGrammarList}};exports.Vocal=t;
2
- //# sourceMappingURL=index.js.map