@ghchinoy/lit-audio-ui 0.2.3 → 0.2.4

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.
@@ -13,7 +13,7 @@ var u = class extends i {
13
13
  start: () => this.start(),
14
14
  stop: () => this.stop(),
15
15
  cancel: () => this.cancel()
16
- }, this.state = "idle", this.simulation = !1, this._fakeTranscript = [
16
+ }, this.state = "idle", this.simulation = !1, this.transcript = "", this.partialTranscript = "", this._fakeTranscript = [
17
17
  "I",
18
18
  " am",
19
19
  " recording",
@@ -32,7 +32,8 @@ var u = class extends i {
32
32
  `;
33
33
  }
34
34
  willUpdate(e) {
35
- e.has("state") && this._updateContext({ state: this.state });
35
+ let t = {};
36
+ e.has("state") && (t.state = this.state), e.has("transcript") && (t.transcript = this.transcript), e.has("partialTranscript") && (t.partialTranscript = this.partialTranscript), Object.keys(t).length > 0 && this._updateContext(t);
36
37
  }
37
38
  async start() {
38
39
  if (this._context.state === "idle") try {
@@ -42,20 +43,22 @@ var u = class extends i {
42
43
  let e = this._audioCtx.createMediaStreamSource(this._stream);
43
44
  this._analyser = this._audioCtx.createAnalyser(), this._analyser.fftSize = 256, e.connect(this._analyser);
44
45
  }
45
- this._updateContext({
46
+ if (this._updateContext({
46
47
  state: "recording",
47
48
  analyserNode: this._analyser,
48
49
  transcript: "",
49
- partialTranscript: "Listening..."
50
- });
51
- let e = 0;
52
- this._transcriptInterval = setInterval(() => {
53
- if (e < this._fakeTranscript.length) {
54
- e === 0 && this._updateContext({ partialTranscript: "" });
55
- let t = this._context.partialTranscript;
56
- this._updateContext({ partialTranscript: t + this._fakeTranscript[e] }), e++;
57
- }
58
- }, 500), this.dispatchEvent(new CustomEvent("speech-start", {
50
+ partialTranscript: this.simulation ? "Listening..." : ""
51
+ }), this.simulation) {
52
+ let e = 0;
53
+ this._transcriptInterval = setInterval(() => {
54
+ if (e < this._fakeTranscript.length) {
55
+ e === 0 && this._updateContext({ partialTranscript: "" });
56
+ let t = this._context.partialTranscript;
57
+ this._updateContext({ partialTranscript: t + this._fakeTranscript[e] }), e++;
58
+ }
59
+ }, 500);
60
+ }
61
+ this.dispatchEvent(new CustomEvent("speech-start", {
59
62
  bubbles: !0,
60
63
  composed: !0,
61
64
  detail: { stream: this._stream }
@@ -68,14 +71,14 @@ var u = class extends i {
68
71
  }
69
72
  }
70
73
  stop() {
71
- this._context.state === "recording" && (clearInterval(this._transcriptInterval), this._cleanupStream(), this._updateContext({
74
+ this._context.state === "recording" && (this._transcriptInterval && clearInterval(this._transcriptInterval), this._cleanupStream(), this._updateContext({
72
75
  state: "processing",
73
- transcript: this._context.partialTranscript,
76
+ transcript: this.simulation ? this._context.partialTranscript : this.transcript,
74
77
  partialTranscript: ""
75
78
  }), this.dispatchEvent(new CustomEvent("speech-stop", {
76
79
  bubbles: !0,
77
80
  composed: !0
78
- })), setTimeout(() => {
81
+ })), this.simulation && setTimeout(() => {
79
82
  this._context.state === "processing" && (this._updateContext({ state: "success" }), setTimeout(() => this.cancel(), 2e3));
80
83
  }, 1500));
81
84
  }
@@ -107,5 +110,5 @@ var u = class extends i {
107
110
  return o`<slot></slot>`;
108
111
  }
109
112
  };
110
- e([n({ context: r }), l()], u.prototype, "_context", void 0), e([c({ type: String })], u.prototype, "state", void 0), e([c({ type: Boolean })], u.prototype, "simulation", void 0), u = e([s("ui-speech-provider")], u);
113
+ e([n({ context: r }), l()], u.prototype, "_context", void 0), e([c({ type: String })], u.prototype, "state", void 0), e([c({ type: Boolean })], u.prototype, "simulation", void 0), e([c({ type: String })], u.prototype, "transcript", void 0), e([c({ type: String })], u.prototype, "partialTranscript", void 0), u = e([s("ui-speech-provider")], u);
111
114
  export { u as UiSpeechProvider };
@@ -1059,11 +1059,11 @@
1059
1059
  <span class="${e?`active`:``}" style="${o}">
1060
1060
  ${this.text}
1061
1061
  </span>
1062
- `}};b([(0,n.property)({type:String})],K.prototype,`text`,void 0),b([(0,n.property)({type:Number})],K.prototype,`duration`,void 0),b([(0,n.property)({type:Number})],K.prototype,`delay`,void 0),b([(0,n.property)({type:Boolean})],K.prototype,`repeat`,void 0),b([(0,n.property)({type:Number})],K.prototype,`repeatDelay`,void 0),b([(0,n.property)({type:Boolean})],K.prototype,`startOnView`,void 0),b([(0,n.property)({type:Boolean})],K.prototype,`once`,void 0),b([(0,n.property)({type:Number})],K.prototype,`spread`,void 0),b([(0,n.property)({type:String})],K.prototype,`color`,void 0),b([(0,n.property)({type:String})],K.prototype,`shimmerColor`,void 0),b([(0,n.state)()],K.prototype,`_isInView`,void 0),K=b([(0,n.customElement)(`ui-shimmering-text`)],K);let q=k(`ui-speech-context`);var J=class extends t.LitElement{constructor(...e){super(...e),this._context={state:`idle`,transcript:``,partialTranscript:``,start:()=>this.start(),stop:()=>this.stop(),cancel:()=>this.cancel()},this.state=`idle`,this.simulation=!1,this._fakeTranscript=[`I`,` am`,` recording`,` a`,` message`,` using`,` atomic`,` components...`]}static{this.styles=t.css`
1062
+ `}};b([(0,n.property)({type:String})],K.prototype,`text`,void 0),b([(0,n.property)({type:Number})],K.prototype,`duration`,void 0),b([(0,n.property)({type:Number})],K.prototype,`delay`,void 0),b([(0,n.property)({type:Boolean})],K.prototype,`repeat`,void 0),b([(0,n.property)({type:Number})],K.prototype,`repeatDelay`,void 0),b([(0,n.property)({type:Boolean})],K.prototype,`startOnView`,void 0),b([(0,n.property)({type:Boolean})],K.prototype,`once`,void 0),b([(0,n.property)({type:Number})],K.prototype,`spread`,void 0),b([(0,n.property)({type:String})],K.prototype,`color`,void 0),b([(0,n.property)({type:String})],K.prototype,`shimmerColor`,void 0),b([(0,n.state)()],K.prototype,`_isInView`,void 0),K=b([(0,n.customElement)(`ui-shimmering-text`)],K);let q=k(`ui-speech-context`);var J=class extends t.LitElement{constructor(...e){super(...e),this._context={state:`idle`,transcript:``,partialTranscript:``,start:()=>this.start(),stop:()=>this.stop(),cancel:()=>this.cancel()},this.state=`idle`,this.simulation=!1,this.transcript=``,this.partialTranscript=``,this._fakeTranscript=[`I`,` am`,` recording`,` a`,` message`,` using`,` atomic`,` components...`]}static{this.styles=t.css`
1063
1063
  :host {
1064
1064
  display: contents;
1065
1065
  }
1066
- `}willUpdate(e){e.has(`state`)&&this._updateContext({state:this.state})}async start(){if(this._context.state===`idle`)try{if(this._updateContext({state:`connecting`}),this.simulation)this._analyser=S();else{this._stream=await navigator.mediaDevices.getUserMedia({audio:!0}),this._audioCtx||=new(window.AudioContext||window.webkitAudioContext);let e=this._audioCtx.createMediaStreamSource(this._stream);this._analyser=this._audioCtx.createAnalyser(),this._analyser.fftSize=256,e.connect(this._analyser)}this._updateContext({state:`recording`,analyserNode:this._analyser,transcript:``,partialTranscript:`Listening...`});let e=0;this._transcriptInterval=setInterval(()=>{if(e<this._fakeTranscript.length){e===0&&this._updateContext({partialTranscript:``});let t=this._context.partialTranscript;this._updateContext({partialTranscript:t+this._fakeTranscript[e]}),e++}},500),this.dispatchEvent(new CustomEvent(`speech-start`,{bubbles:!0,composed:!0,detail:{stream:this._stream}}))}catch(e){console.error(`Failed to start speech recording`,e),this._updateContext({state:`error`,error:e.message})}}stop(){this._context.state===`recording`&&(clearInterval(this._transcriptInterval),this._cleanupStream(),this._updateContext({state:`processing`,transcript:this._context.partialTranscript,partialTranscript:``}),this.dispatchEvent(new CustomEvent(`speech-stop`,{bubbles:!0,composed:!0})),setTimeout(()=>{this._context.state===`processing`&&(this._updateContext({state:`success`}),setTimeout(()=>this.cancel(),2e3))},1500))}cancel(){clearInterval(this._transcriptInterval),this._cleanupStream(),this._updateContext({state:`idle`,transcript:``,partialTranscript:``,analyserNode:void 0}),this.dispatchEvent(new CustomEvent(`speech-cancel`,{bubbles:!0,composed:!0}))}_cleanupStream(){this._stream&&=(this._stream.getTracks().forEach(e=>e.stop()),void 0)}_updateContext(e){this._context={...this._context,...e},e.state&&(this.state=e.state),this.dispatchEvent(new CustomEvent(`state-change`,{bubbles:!0,composed:!0,detail:this._context}))}render(){return t.html`<slot></slot>`}};b([P({context:q}),(0,n.state)()],J.prototype,`_context`,void 0),b([(0,n.property)({type:String})],J.prototype,`state`,void 0),b([(0,n.property)({type:Boolean})],J.prototype,`simulation`,void 0),J=b([(0,n.customElement)(`ui-speech-provider`)],J);var Y=class extends t.LitElement{constructor(...e){super(...e),this.size=`default`}static{this.styles=t.css`
1066
+ `}willUpdate(e){let t={};e.has(`state`)&&(t.state=this.state),e.has(`transcript`)&&(t.transcript=this.transcript),e.has(`partialTranscript`)&&(t.partialTranscript=this.partialTranscript),Object.keys(t).length>0&&this._updateContext(t)}async start(){if(this._context.state===`idle`)try{if(this._updateContext({state:`connecting`}),this.simulation)this._analyser=S();else{this._stream=await navigator.mediaDevices.getUserMedia({audio:!0}),this._audioCtx||=new(window.AudioContext||window.webkitAudioContext);let e=this._audioCtx.createMediaStreamSource(this._stream);this._analyser=this._audioCtx.createAnalyser(),this._analyser.fftSize=256,e.connect(this._analyser)}if(this._updateContext({state:`recording`,analyserNode:this._analyser,transcript:``,partialTranscript:this.simulation?`Listening...`:``}),this.simulation){let e=0;this._transcriptInterval=setInterval(()=>{if(e<this._fakeTranscript.length){e===0&&this._updateContext({partialTranscript:``});let t=this._context.partialTranscript;this._updateContext({partialTranscript:t+this._fakeTranscript[e]}),e++}},500)}this.dispatchEvent(new CustomEvent(`speech-start`,{bubbles:!0,composed:!0,detail:{stream:this._stream}}))}catch(e){console.error(`Failed to start speech recording`,e),this._updateContext({state:`error`,error:e.message})}}stop(){this._context.state===`recording`&&(this._transcriptInterval&&clearInterval(this._transcriptInterval),this._cleanupStream(),this._updateContext({state:`processing`,transcript:this.simulation?this._context.partialTranscript:this.transcript,partialTranscript:``}),this.dispatchEvent(new CustomEvent(`speech-stop`,{bubbles:!0,composed:!0})),this.simulation&&setTimeout(()=>{this._context.state===`processing`&&(this._updateContext({state:`success`}),setTimeout(()=>this.cancel(),2e3))},1500))}cancel(){clearInterval(this._transcriptInterval),this._cleanupStream(),this._updateContext({state:`idle`,transcript:``,partialTranscript:``,analyserNode:void 0}),this.dispatchEvent(new CustomEvent(`speech-cancel`,{bubbles:!0,composed:!0}))}_cleanupStream(){this._stream&&=(this._stream.getTracks().forEach(e=>e.stop()),void 0)}_updateContext(e){this._context={...this._context,...e},e.state&&(this.state=e.state),this.dispatchEvent(new CustomEvent(`state-change`,{bubbles:!0,composed:!0,detail:this._context}))}render(){return t.html`<slot></slot>`}};b([P({context:q}),(0,n.state)()],J.prototype,`_context`,void 0),b([(0,n.property)({type:String})],J.prototype,`state`,void 0),b([(0,n.property)({type:Boolean})],J.prototype,`simulation`,void 0),b([(0,n.property)({type:String})],J.prototype,`transcript`,void 0),b([(0,n.property)({type:String})],J.prototype,`partialTranscript`,void 0),J=b([(0,n.customElement)(`ui-speech-provider`)],J);var Y=class extends t.LitElement{constructor(...e){super(...e),this.size=`default`}static{this.styles=t.css`
1067
1067
  :host {
1068
1068
  display: inline-block;
1069
1069
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghchinoy/lit-audio-ui",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "A pure Lit WebComponents port of modern audio UI components",
5
5
  "author": "G. Hussain Chinoy",
6
6
  "license": "Apache-2.0",