@meersagor/wavesurfer-vue 0.0.5 → 0.1.1
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/dist/@meersagor-wavesurfer-vue.cjs +1 -0
- package/dist/@meersagor-wavesurfer-vue.js +183 -181
- package/dist/src/components/WaveSurferPlayer.vue.d.ts +7 -0
- package/dist/{composables → src/composables}/useWaveSurfer.d.ts +1 -0
- package/dist/src/composables/useWaveSurferInstance.d.ts +999 -0
- package/dist/src/composables/useWaveSurferRecorder.d.ts +1053 -0
- package/dist/src/composables/useWaveSurferState.d.ts +8 -0
- package/dist/src/eventsEmitter/index.d.ts +2 -0
- package/dist/{index.d.ts → src/index.d.ts} +1 -1
- package/dist/src/types/index.d.ts +10 -0
- package/dist/vite.config.d.ts +2 -0
- package/package.json +25 -27
- package/dist/@meersagor-wavesurfer-vue.umd.cjs +0 -14
- package/dist/components/WaveSurferPlayer.vue.d.ts +0 -2
- package/dist/composables/useWaveSurferInstance.d.ts +0 -3
- package/dist/composables/useWaveSurferRecorder.d.ts +0 -11
- package/dist/composables/useWaveSurferState.d.ts +0 -6
- package/dist/tsconfig.app.tsbuildinfo +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("vue"),b=require("wavesurfer.js"),R=({containerRef:n,options:e})=>{const i=a.ref(null),t=()=>{n.value&&(i.value=b.create({container:n.value,...e}))},r=()=>{i.value&&(i.value.destroy(),i.value=null)};return a.onMounted(()=>{t()}),a.onUnmounted(()=>{r()}),{waveSurfer:i}},M=n=>{const e=a.ref(!1),i=a.ref(!1),t=a.ref(0),r=a.ref(0),o=()=>{e.value=!1,i.value=!1,t.value=0},s=m=>{e.value=!0,i.value=!1,t.value=0,r.value=m},u=()=>{i.value=!0},d=()=>{i.value=!1},c=()=>{n.value&&(t.value=n.value.getCurrentTime())},l=()=>{e.value=!1,i.value=!1};return a.onMounted(()=>{n.value&&(n.value.on("load",o),n.value.on("ready",s),n.value.on("play",u),n.value.on("pause",d),n.value.on("timeupdate",c),n.value.on("destroy",l))}),a.onUnmounted(()=>{n.value&&n.value.unAll()}),{isReady:e,isPlaying:i,currentTime:t,totalDuration:r}},y=({containerRef:n,options:e})=>{const{waveSurfer:i}=R({containerRef:n,options:e}),{isReady:t,totalDuration:r,isPlaying:o,currentTime:s}=M(i);return{waveSurfer:i,isReady:t,totalDuration:r,isPlaying:o,currentTime:s}},D=["audioprocess","click","dblclick","decode","drag","finish","init","interaction","load","loading","pause","play","ready","redraw","redrawcomplete","scroll","seeking","timeupdate","zoom"],T=a.defineComponent({__name:"WaveSurferPlayer",props:{options:{}},setup(n){const e=n,i=a.ref(null),{waveSurfer:t}=y({containerRef:i,options:e.options}),r=a.getCurrentInstance();return a.onMounted(()=>{D.forEach(o=>{t.value?.on(o,(...s)=>{r?.emit(o,...s)})}),r?.emit("waveSurfer",t.value)}),(o,s)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:i},null,512))}});function w(n,e,i,t){return new(i||(i=Promise))(function(r,o){function s(c){try{d(t.next(c))}catch(l){o(l)}}function u(c){try{d(t.throw(c))}catch(l){o(l)}}function d(c){var l;c.done?r(c.value):(l=c.value,l instanceof i?l:new i(function(m){m(l)})).then(s,u)}d((t=t.apply(n,[])).next())})}class S{constructor(){this.listeners={}}on(e,i,t){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(i),t?.once){const r=()=>{this.un(e,r),this.un(e,i)};return this.on(e,r),r}return()=>this.un(e,i)}un(e,i){var t;(t=this.listeners[e])===null||t===void 0||t.delete(i)}once(e,i){return this.on(e,i,{once:!0})}unAll(){this.listeners={}}emit(e,...i){this.listeners[e]&&this.listeners[e].forEach(t=>t(...i))}}class O extends S{constructor(e){super(),this.subscriptions=[],this.options=e}onInit(){}_init(e){this.wavesurfer=e,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(e=>e())}}class A extends S{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}const E=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class W extends O{constructor(e){var i,t,r,o,s,u;super(Object.assign(Object.assign({},e),{audioBitsPerSecond:(i=e.audioBitsPerSecond)!==null&&i!==void 0?i:128e3,scrollingWaveform:(t=e.scrollingWaveform)!==null&&t!==void 0&&t,scrollingWaveformWindow:(r=e.scrollingWaveformWindow)!==null&&r!==void 0?r:5,continuousWaveform:(o=e.continuousWaveform)!==null&&o!==void 0&&o,renderRecordedAudio:(s=e.renderRecordedAudio)===null||s===void 0||s,mediaRecorderTimeslice:(u=e.mediaRecorderTimeslice)!==null&&u!==void 0?u:void 0})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1,this.lastStartTime=0,this.lastDuration=0,this.duration=0,this.timer=new A,this.subscriptions.push(this.timer.on("tick",()=>{const d=performance.now()-this.lastStartTime;this.duration=this.isPaused()?this.duration:this.lastDuration+d,this.emit("record-progress",this.duration)}))}static create(e){return new W(e||{})}renderMicStream(e){var i;const t=new AudioContext,r=t.createMediaStreamSource(e),o=t.createAnalyser();r.connect(o),this.options.continuousWaveform&&(o.fftSize=32);const s=o.frequencyBinCount,u=new Float32Array(s);let d=0;this.wavesurfer&&((i=this.originalOptions)!==null&&i!==void 0||(this.originalOptions=Object.assign({},this.wavesurfer.options)),this.wavesurfer.options.interact=!1,this.options.scrollingWaveform&&(this.wavesurfer.options.cursorWidth=0));const c=setInterval(()=>{var l,m,g,h;if(!this.isWaveformPaused){if(o.getFloatTimeDomainData(u),this.options.scrollingWaveform){const f=Math.floor((this.options.scrollingWaveformWindow||0)*t.sampleRate),v=Math.min(f,this.dataWindow?this.dataWindow.length+s:s),p=new Float32Array(f);if(this.dataWindow){const P=Math.max(0,f-this.dataWindow.length);p.set(this.dataWindow.slice(-v+s),P)}p.set(u,f-s),this.dataWindow=p}else if(this.options.continuousWaveform){if(!this.dataWindow){const v=this.options.continuousWaveformDuration?Math.round(100*this.options.continuousWaveformDuration):((m=(l=this.wavesurfer)===null||l===void 0?void 0:l.getWidth())!==null&&m!==void 0?m:0)*window.devicePixelRatio;this.dataWindow=new Float32Array(v)}let f=0;for(let v=0;v<s;v++){const p=Math.abs(u[v]);p>f&&(f=p)}if(d+1>this.dataWindow.length){const v=new Float32Array(2*this.dataWindow.length);v.set(this.dataWindow,0),this.dataWindow=v}this.dataWindow[d]=f,d++}else this.dataWindow=u;if(this.wavesurfer){const f=((h=(g=this.dataWindow)===null||g===void 0?void 0:g.length)!==null&&h!==void 0?h:0)/100;this.wavesurfer.load("",[this.dataWindow],this.options.scrollingWaveform?this.options.scrollingWaveformWindow:f).then(()=>{this.wavesurfer&&this.options.continuousWaveform&&(this.wavesurfer.setTime(this.getDuration()/1e3),this.wavesurfer.options.minPxPerSec||this.wavesurfer.setOptions({minPxPerSec:this.wavesurfer.getWidth()/this.wavesurfer.getDuration()}))}).catch(v=>{console.error("Error rendering real-time recording data:",v)})}}},10);return{onDestroy:()=>{clearInterval(c),r?.disconnect(),t?.close()},onEnd:()=>{this.isWaveformPaused=!0,clearInterval(c),this.stopMic()}}}startMic(e){return w(this,void 0,void 0,function*(){let i;try{i=yield navigator.mediaDevices.getUserMedia({audio:!e?.deviceId||{deviceId:e.deviceId}})}catch(o){throw new Error("Error accessing the microphone: "+o.message)}const{onDestroy:t,onEnd:r}=this.renderMicStream(i);return this.subscriptions.push(this.once("destroy",t)),this.subscriptions.push(this.once("record-end",r)),this.stream=i,i})}stopMic(){this.stream&&(this.stream.getTracks().forEach(e=>e.stop()),this.stream=null,this.mediaRecorder=null)}startRecording(e){return w(this,void 0,void 0,function*(){const i=this.stream||(yield this.startMic(e));this.dataWindow=null;const t=this.mediaRecorder||new MediaRecorder(i,{mimeType:this.options.mimeType||E.find(s=>MediaRecorder.isTypeSupported(s)),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=t,this.stopRecording();const r=[];t.ondataavailable=s=>{s.data.size>0&&r.push(s.data),this.emit("record-data-available",s.data)};const o=s=>{var u;const d=new Blob(r,{type:t.mimeType});this.emit(s,d),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),(u=this.wavesurfer)===null||u===void 0||u.load(URL.createObjectURL(d)))};t.onpause=()=>o("record-pause"),t.onstop=()=>o("record-end"),t.start(this.options.mediaRecorderTimeslice),this.lastStartTime=performance.now(),this.lastDuration=0,this.duration=0,this.isWaveformPaused=!1,this.timer.start(),this.emit("record-start")})}getDuration(){return this.duration}isRecording(){var e;return((e=this.mediaRecorder)===null||e===void 0?void 0:e.state)==="recording"}isPaused(){var e;return((e=this.mediaRecorder)===null||e===void 0?void 0:e.state)==="paused"}isActive(){var e;return((e=this.mediaRecorder)===null||e===void 0?void 0:e.state)!=="inactive"}stopRecording(){var e;this.isActive()&&((e=this.mediaRecorder)===null||e===void 0||e.stop(),this.timer.stop())}pauseRecording(){var e,i;this.isRecording()&&(this.isWaveformPaused=!0,(e=this.mediaRecorder)===null||e===void 0||e.requestData(),(i=this.mediaRecorder)===null||i===void 0||i.pause(),this.timer.stop(),this.lastDuration=this.duration)}resumeRecording(){var e;this.isPaused()&&(this.isWaveformPaused=!1,(e=this.mediaRecorder)===null||e===void 0||e.resume(),this.timer.start(),this.lastStartTime=performance.now(),this.emit("record-resume"))}static getAvailableAudioDevices(){return w(this,void 0,void 0,function*(){return navigator.mediaDevices.enumerateDevices().then(e=>e.filter(i=>i.kind==="audioinput"))})}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.setOptions(this.originalOptions),delete this.originalOptions)}}const I=({containerRef:n,options:e})=>{const{waveSurfer:i}=R({containerRef:n,options:e}),t=a.ref(null),r=a.ref(0),o=a.ref(!1),s=a.ref(!1),u=a.computed(()=>[Math.floor(r.value%36e5/6e4),Math.floor(r.value%6e4/1e3)].map(h=>h<10?"0"+h:h).join(":")),d=a.computed(()=>o.value||!s.value),c=()=>{t.value&&t.value?.on("record-progress",h=>{r.value=h})},l=()=>{if(t.value?.isRecording()||t.value?.isPaused()){t.value?.stopRecording(),o.value=!1,s.value=!0;return}t.value?.startRecording(),o.value=!0,s.value=!1,c()},m=()=>new Promise(h=>{let f;(t.value?.isRecording()||t.value?.isPaused())&&(t.value?.stopRecording(),o.value=!1,s.value=!1),t.value?.on("record-end",v=>{f=v,h(f)})}),g=()=>{if(t.value?.isPaused()){t.value?.resumeRecording(),o.value=!0,s.value=!1;return}o.value=!1,s.value=!0,t.value?.pauseRecording()};return a.onMounted(()=>{const h=i.value?.registerPlugin(W.create({renderRecordedAudio:!1}));h&&(t.value=h)}),{waveSurfer:i,waveSurferRecorder:t,currentTime:u,startRecording:l,stopRecording:m,pauseRecording:g,isRecording:o,isPaused:s,isPauseResume:d}};exports.WaveSurferPlayer=T;exports.useWaveSurfer=y;exports.useWaveSurferRecorder=I;
|
|
@@ -1,139 +1,124 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
import
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
n.value && (
|
|
1
|
+
import { ref as m, onMounted as w, onUnmounted as S, defineComponent as T, getCurrentInstance as M, openBlock as A, createElementBlock as O, computed as y } from "vue";
|
|
2
|
+
import E from "wavesurfer.js";
|
|
3
|
+
const P = ({ containerRef: n, options: e }) => {
|
|
4
|
+
const i = m(null), t = () => {
|
|
5
|
+
n.value && (i.value = E.create({
|
|
6
6
|
container: n.value,
|
|
7
7
|
...e
|
|
8
8
|
}));
|
|
9
|
-
},
|
|
10
|
-
|
|
9
|
+
}, o = () => {
|
|
10
|
+
i.value && (i.value.destroy(), i.value = null);
|
|
11
11
|
};
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
}),
|
|
15
|
-
|
|
16
|
-
}), { waveSurfer:
|
|
17
|
-
},
|
|
18
|
-
const e =
|
|
19
|
-
e.value = !1,
|
|
20
|
-
},
|
|
21
|
-
e.value = !0,
|
|
12
|
+
return w(() => {
|
|
13
|
+
t();
|
|
14
|
+
}), S(() => {
|
|
15
|
+
o();
|
|
16
|
+
}), { waveSurfer: i };
|
|
17
|
+
}, I = (n) => {
|
|
18
|
+
const e = m(!1), i = m(!1), t = m(0), o = m(0), r = () => {
|
|
19
|
+
e.value = !1, i.value = !1, t.value = 0;
|
|
20
|
+
}, s = (f) => {
|
|
21
|
+
e.value = !0, i.value = !1, t.value = 0, o.value = f;
|
|
22
|
+
}, a = () => {
|
|
23
|
+
i.value = !0;
|
|
22
24
|
}, u = () => {
|
|
23
|
-
|
|
24
|
-
}, d = () => {
|
|
25
|
-
t.value = !1;
|
|
25
|
+
i.value = !1;
|
|
26
26
|
}, l = () => {
|
|
27
|
-
n.value && (
|
|
28
|
-
},
|
|
29
|
-
e.value = !1,
|
|
27
|
+
n.value && (t.value = n.value.getCurrentTime());
|
|
28
|
+
}, d = () => {
|
|
29
|
+
e.value = !1, i.value = !1;
|
|
30
30
|
};
|
|
31
|
-
return
|
|
32
|
-
n.value && (n.value.on("load", r), n.value.on("ready",
|
|
33
|
-
}),
|
|
31
|
+
return w(() => {
|
|
32
|
+
n.value && (n.value.on("load", r), n.value.on("ready", s), n.value.on("play", a), n.value.on("pause", u), n.value.on("timeupdate", l), n.value.on("destroy", d));
|
|
33
|
+
}), S(() => {
|
|
34
34
|
n.value && n.value.unAll();
|
|
35
35
|
}), {
|
|
36
36
|
isReady: e,
|
|
37
|
-
isPlaying:
|
|
38
|
-
currentTime:
|
|
39
|
-
totalDuration:
|
|
37
|
+
isPlaying: i,
|
|
38
|
+
currentTime: t,
|
|
39
|
+
totalDuration: o
|
|
40
40
|
};
|
|
41
|
-
},
|
|
42
|
-
const { waveSurfer:
|
|
41
|
+
}, k = ({ containerRef: n, options: e }) => {
|
|
42
|
+
const { waveSurfer: i } = P({ containerRef: n, options: e }), { isReady: t, totalDuration: o, isPlaying: r, currentTime: s } = I(i);
|
|
43
43
|
return {
|
|
44
|
-
waveSurfer:
|
|
45
|
-
isReady:
|
|
46
|
-
totalDuration:
|
|
44
|
+
waveSurfer: i,
|
|
45
|
+
isReady: t,
|
|
46
|
+
totalDuration: o,
|
|
47
47
|
isPlaying: r,
|
|
48
|
-
currentTime:
|
|
48
|
+
currentTime: s
|
|
49
49
|
};
|
|
50
|
-
},
|
|
50
|
+
}, x = ["audioprocess", "click", "dblclick", "decode", "drag", "finish", "init", "interaction", "load", "loading", "pause", "play", "ready", "redraw", "redrawcomplete", "scroll", "seeking", "timeupdate", "zoom"], U = /* @__PURE__ */ T({
|
|
51
51
|
__name: "WaveSurferPlayer",
|
|
52
52
|
props: {
|
|
53
53
|
options: {}
|
|
54
54
|
},
|
|
55
55
|
setup(n) {
|
|
56
|
-
const e = n,
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
s == null || s.emit(r, ...u);
|
|
56
|
+
const e = n, i = m(null), { waveSurfer: t } = k({ containerRef: i, options: e.options }), o = M();
|
|
57
|
+
return w(() => {
|
|
58
|
+
x.forEach((r) => {
|
|
59
|
+
t.value?.on(r, (...s) => {
|
|
60
|
+
o?.emit(r, ...s);
|
|
62
61
|
});
|
|
63
|
-
}),
|
|
64
|
-
}), (r,
|
|
62
|
+
}), o?.emit("waveSurfer", t.value);
|
|
63
|
+
}), (r, s) => (A(), O("div", {
|
|
65
64
|
ref_key: "containerRef",
|
|
66
|
-
ref:
|
|
65
|
+
ref: i
|
|
67
66
|
}, null, 512));
|
|
68
67
|
}
|
|
69
68
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
74
|
-
purpose with or without fee is hereby granted.
|
|
75
|
-
|
|
76
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
77
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
78
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
79
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
80
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
81
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
82
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
83
|
-
***************************************************************************** */
|
|
84
|
-
function w(n, e, t, i) {
|
|
85
|
-
return new (t || (t = Promise))(function(s, r) {
|
|
86
|
-
function o(l) {
|
|
69
|
+
function W(n, e, i, t) {
|
|
70
|
+
return new (i || (i = Promise))(function(o, r) {
|
|
71
|
+
function s(l) {
|
|
87
72
|
try {
|
|
88
|
-
|
|
89
|
-
} catch (
|
|
90
|
-
r(
|
|
73
|
+
u(t.next(l));
|
|
74
|
+
} catch (d) {
|
|
75
|
+
r(d);
|
|
91
76
|
}
|
|
92
77
|
}
|
|
93
|
-
function
|
|
78
|
+
function a(l) {
|
|
94
79
|
try {
|
|
95
|
-
|
|
96
|
-
} catch (
|
|
97
|
-
r(
|
|
80
|
+
u(t.throw(l));
|
|
81
|
+
} catch (d) {
|
|
82
|
+
r(d);
|
|
98
83
|
}
|
|
99
84
|
}
|
|
100
|
-
function
|
|
101
|
-
var
|
|
102
|
-
l.done ?
|
|
103
|
-
|
|
104
|
-
})).then(
|
|
85
|
+
function u(l) {
|
|
86
|
+
var d;
|
|
87
|
+
l.done ? o(l.value) : (d = l.value, d instanceof i ? d : new i(function(f) {
|
|
88
|
+
f(d);
|
|
89
|
+
})).then(s, a);
|
|
105
90
|
}
|
|
106
|
-
|
|
91
|
+
u((t = t.apply(n, [])).next());
|
|
107
92
|
});
|
|
108
93
|
}
|
|
109
|
-
class
|
|
94
|
+
class b {
|
|
110
95
|
constructor() {
|
|
111
96
|
this.listeners = {};
|
|
112
97
|
}
|
|
113
|
-
on(e,
|
|
114
|
-
if (this.listeners[e] || (this.listeners[e] = /* @__PURE__ */ new Set()), this.listeners[e].add(
|
|
115
|
-
const
|
|
116
|
-
this.un(e,
|
|
98
|
+
on(e, i, t) {
|
|
99
|
+
if (this.listeners[e] || (this.listeners[e] = /* @__PURE__ */ new Set()), this.listeners[e].add(i), t?.once) {
|
|
100
|
+
const o = () => {
|
|
101
|
+
this.un(e, o), this.un(e, i);
|
|
117
102
|
};
|
|
118
|
-
return this.on(e,
|
|
103
|
+
return this.on(e, o), o;
|
|
119
104
|
}
|
|
120
|
-
return () => this.un(e,
|
|
105
|
+
return () => this.un(e, i);
|
|
121
106
|
}
|
|
122
|
-
un(e,
|
|
123
|
-
var
|
|
124
|
-
(
|
|
107
|
+
un(e, i) {
|
|
108
|
+
var t;
|
|
109
|
+
(t = this.listeners[e]) === null || t === void 0 || t.delete(i);
|
|
125
110
|
}
|
|
126
|
-
once(e,
|
|
127
|
-
return this.on(e,
|
|
111
|
+
once(e, i) {
|
|
112
|
+
return this.on(e, i, { once: !0 });
|
|
128
113
|
}
|
|
129
114
|
unAll() {
|
|
130
115
|
this.listeners = {};
|
|
131
116
|
}
|
|
132
|
-
emit(e, ...
|
|
133
|
-
this.listeners[e] && this.listeners[e].forEach((
|
|
117
|
+
emit(e, ...i) {
|
|
118
|
+
this.listeners[e] && this.listeners[e].forEach((t) => t(...i));
|
|
134
119
|
}
|
|
135
120
|
}
|
|
136
|
-
class
|
|
121
|
+
class B extends b {
|
|
137
122
|
constructor(e) {
|
|
138
123
|
super(), this.subscriptions = [], this.options = e;
|
|
139
124
|
}
|
|
@@ -146,7 +131,7 @@ class _ extends D {
|
|
|
146
131
|
this.emit("destroy"), this.subscriptions.forEach((e) => e());
|
|
147
132
|
}
|
|
148
133
|
}
|
|
149
|
-
class
|
|
134
|
+
class _ extends b {
|
|
150
135
|
constructor() {
|
|
151
136
|
super(...arguments), this.unsubscribe = () => {
|
|
152
137
|
};
|
|
@@ -165,76 +150,98 @@ class q extends D {
|
|
|
165
150
|
this.unsubscribe();
|
|
166
151
|
}
|
|
167
152
|
}
|
|
168
|
-
const
|
|
169
|
-
class
|
|
153
|
+
const F = ["audio/webm", "audio/wav", "audio/mpeg", "audio/mp4", "audio/mp3"];
|
|
154
|
+
class R extends B {
|
|
170
155
|
constructor(e) {
|
|
171
|
-
var t,
|
|
172
|
-
super(Object.assign(Object.assign({}, e), { audioBitsPerSecond: (
|
|
173
|
-
const
|
|
174
|
-
this.duration = this.isPaused() ? this.duration : this.lastDuration +
|
|
156
|
+
var i, t, o, r, s, a;
|
|
157
|
+
super(Object.assign(Object.assign({}, e), { audioBitsPerSecond: (i = e.audioBitsPerSecond) !== null && i !== void 0 ? i : 128e3, scrollingWaveform: (t = e.scrollingWaveform) !== null && t !== void 0 && t, scrollingWaveformWindow: (o = e.scrollingWaveformWindow) !== null && o !== void 0 ? o : 5, continuousWaveform: (r = e.continuousWaveform) !== null && r !== void 0 && r, renderRecordedAudio: (s = e.renderRecordedAudio) === null || s === void 0 || s, mediaRecorderTimeslice: (a = e.mediaRecorderTimeslice) !== null && a !== void 0 ? a : void 0 })), this.stream = null, this.mediaRecorder = null, this.dataWindow = null, this.isWaveformPaused = !1, this.lastStartTime = 0, this.lastDuration = 0, this.duration = 0, this.timer = new _(), this.subscriptions.push(this.timer.on("tick", () => {
|
|
158
|
+
const u = performance.now() - this.lastStartTime;
|
|
159
|
+
this.duration = this.isPaused() ? this.duration : this.lastDuration + u, this.emit("record-progress", this.duration);
|
|
175
160
|
}));
|
|
176
161
|
}
|
|
177
162
|
static create(e) {
|
|
178
|
-
return new
|
|
163
|
+
return new R(e || {});
|
|
179
164
|
}
|
|
180
165
|
renderMicStream(e) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
166
|
+
var i;
|
|
167
|
+
const t = new AudioContext(), o = t.createMediaStreamSource(e), r = t.createAnalyser();
|
|
168
|
+
o.connect(r), this.options.continuousWaveform && (r.fftSize = 32);
|
|
169
|
+
const s = r.frequencyBinCount, a = new Float32Array(s);
|
|
170
|
+
let u = 0;
|
|
171
|
+
this.wavesurfer && ((i = this.originalOptions) !== null && i !== void 0 || (this.originalOptions = Object.assign({}, this.wavesurfer.options)), this.wavesurfer.options.interact = !1, this.options.scrollingWaveform && (this.wavesurfer.options.cursorWidth = 0));
|
|
172
|
+
const l = setInterval(() => {
|
|
173
|
+
var d, f, g, c;
|
|
174
|
+
if (!this.isWaveformPaused) {
|
|
175
|
+
if (r.getFloatTimeDomainData(a), this.options.scrollingWaveform) {
|
|
176
|
+
const v = Math.floor((this.options.scrollingWaveformWindow || 0) * t.sampleRate), h = Math.min(v, this.dataWindow ? this.dataWindow.length + s : s), p = new Float32Array(v);
|
|
177
|
+
if (this.dataWindow) {
|
|
178
|
+
const D = Math.max(0, v - this.dataWindow.length);
|
|
179
|
+
p.set(this.dataWindow.slice(-h + s), D);
|
|
180
|
+
}
|
|
181
|
+
p.set(a, v - s), this.dataWindow = p;
|
|
182
|
+
} else if (this.options.continuousWaveform) {
|
|
183
|
+
if (!this.dataWindow) {
|
|
184
|
+
const h = this.options.continuousWaveformDuration ? Math.round(100 * this.options.continuousWaveformDuration) : ((f = (d = this.wavesurfer) === null || d === void 0 ? void 0 : d.getWidth()) !== null && f !== void 0 ? f : 0) * window.devicePixelRatio;
|
|
185
|
+
this.dataWindow = new Float32Array(h);
|
|
186
|
+
}
|
|
187
|
+
let v = 0;
|
|
188
|
+
for (let h = 0; h < s; h++) {
|
|
189
|
+
const p = Math.abs(a[h]);
|
|
190
|
+
p > v && (v = p);
|
|
191
|
+
}
|
|
192
|
+
if (u + 1 > this.dataWindow.length) {
|
|
193
|
+
const h = new Float32Array(2 * this.dataWindow.length);
|
|
194
|
+
h.set(this.dataWindow, 0), this.dataWindow = h;
|
|
195
|
+
}
|
|
196
|
+
this.dataWindow[u] = v, u++;
|
|
197
|
+
} else this.dataWindow = a;
|
|
198
|
+
if (this.wavesurfer) {
|
|
199
|
+
const v = ((c = (g = this.dataWindow) === null || g === void 0 ? void 0 : g.length) !== null && c !== void 0 ? c : 0) / 100;
|
|
200
|
+
this.wavesurfer.load("", [this.dataWindow], this.options.scrollingWaveform ? this.options.scrollingWaveformWindow : v).then(() => {
|
|
201
|
+
this.wavesurfer && this.options.continuousWaveform && (this.wavesurfer.setTime(this.getDuration() / 1e3), this.wavesurfer.options.minPxPerSec || this.wavesurfer.setOptions({ minPxPerSec: this.wavesurfer.getWidth() / this.wavesurfer.getDuration() }));
|
|
202
|
+
}).catch((h) => {
|
|
203
|
+
console.error("Error rendering real-time recording data:", h);
|
|
204
|
+
});
|
|
194
205
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
this.wavesurfer && ((c = this.originalOptions) !== null && c !== void 0 || (this.originalOptions = { cursorWidth: this.wavesurfer.options.cursorWidth, interact: this.wavesurfer.options.interact }), this.wavesurfer.options.cursorWidth = 0, this.wavesurfer.options.interact = !1, this.wavesurfer.load("", [this.dataWindow], p)), u = requestAnimationFrame(l);
|
|
200
|
-
};
|
|
201
|
-
return l(), { onDestroy: () => {
|
|
202
|
-
cancelAnimationFrame(u), i == null || i.disconnect(), t == null || t.close();
|
|
206
|
+
}
|
|
207
|
+
}, 10);
|
|
208
|
+
return { onDestroy: () => {
|
|
209
|
+
clearInterval(l), o?.disconnect(), t?.close();
|
|
203
210
|
}, onEnd: () => {
|
|
204
|
-
this.isWaveformPaused = !0,
|
|
211
|
+
this.isWaveformPaused = !0, clearInterval(l), this.stopMic();
|
|
205
212
|
} };
|
|
206
213
|
}
|
|
207
214
|
startMic(e) {
|
|
208
|
-
return
|
|
209
|
-
let
|
|
215
|
+
return W(this, void 0, void 0, function* () {
|
|
216
|
+
let i;
|
|
210
217
|
try {
|
|
211
|
-
|
|
218
|
+
i = yield navigator.mediaDevices.getUserMedia({ audio: !e?.deviceId || { deviceId: e.deviceId } });
|
|
212
219
|
} catch (r) {
|
|
213
220
|
throw new Error("Error accessing the microphone: " + r.message);
|
|
214
221
|
}
|
|
215
|
-
const { onDestroy:
|
|
216
|
-
return this.subscriptions.push(this.once("destroy",
|
|
222
|
+
const { onDestroy: t, onEnd: o } = this.renderMicStream(i);
|
|
223
|
+
return this.subscriptions.push(this.once("destroy", t)), this.subscriptions.push(this.once("record-end", o)), this.stream = i, i;
|
|
217
224
|
});
|
|
218
225
|
}
|
|
219
226
|
stopMic() {
|
|
220
227
|
this.stream && (this.stream.getTracks().forEach((e) => e.stop()), this.stream = null, this.mediaRecorder = null);
|
|
221
228
|
}
|
|
222
229
|
startRecording(e) {
|
|
223
|
-
return
|
|
224
|
-
const
|
|
230
|
+
return W(this, void 0, void 0, function* () {
|
|
231
|
+
const i = this.stream || (yield this.startMic(e));
|
|
225
232
|
this.dataWindow = null;
|
|
226
|
-
const
|
|
227
|
-
this.mediaRecorder =
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
233
|
+
const t = this.mediaRecorder || new MediaRecorder(i, { mimeType: this.options.mimeType || F.find((s) => MediaRecorder.isTypeSupported(s)), audioBitsPerSecond: this.options.audioBitsPerSecond });
|
|
234
|
+
this.mediaRecorder = t, this.stopRecording();
|
|
235
|
+
const o = [];
|
|
236
|
+
t.ondataavailable = (s) => {
|
|
237
|
+
s.data.size > 0 && o.push(s.data), this.emit("record-data-available", s.data);
|
|
231
238
|
};
|
|
232
|
-
const r = (
|
|
233
|
-
var
|
|
234
|
-
const
|
|
235
|
-
this.emit(
|
|
239
|
+
const r = (s) => {
|
|
240
|
+
var a;
|
|
241
|
+
const u = new Blob(o, { type: t.mimeType });
|
|
242
|
+
this.emit(s, u), this.options.renderRecordedAudio && (this.applyOriginalOptionsIfNeeded(), (a = this.wavesurfer) === null || a === void 0 || a.load(URL.createObjectURL(u)));
|
|
236
243
|
};
|
|
237
|
-
|
|
244
|
+
t.onpause = () => r("record-pause"), t.onstop = () => r("record-end"), t.start(this.options.mediaRecorderTimeslice), this.lastStartTime = performance.now(), this.lastDuration = 0, this.duration = 0, this.isWaveformPaused = !1, this.timer.start(), this.emit("record-start");
|
|
238
245
|
});
|
|
239
246
|
}
|
|
240
247
|
getDuration() {
|
|
@@ -257,75 +264,70 @@ class y extends _ {
|
|
|
257
264
|
this.isActive() && ((e = this.mediaRecorder) === null || e === void 0 || e.stop(), this.timer.stop());
|
|
258
265
|
}
|
|
259
266
|
pauseRecording() {
|
|
260
|
-
var e,
|
|
261
|
-
this.isRecording() && (this.isWaveformPaused = !0, (e = this.mediaRecorder) === null || e === void 0 || e.requestData(), (
|
|
267
|
+
var e, i;
|
|
268
|
+
this.isRecording() && (this.isWaveformPaused = !0, (e = this.mediaRecorder) === null || e === void 0 || e.requestData(), (i = this.mediaRecorder) === null || i === void 0 || i.pause(), this.timer.stop(), this.lastDuration = this.duration);
|
|
262
269
|
}
|
|
263
270
|
resumeRecording() {
|
|
264
271
|
var e;
|
|
265
272
|
this.isPaused() && (this.isWaveformPaused = !1, (e = this.mediaRecorder) === null || e === void 0 || e.resume(), this.timer.start(), this.lastStartTime = performance.now(), this.emit("record-resume"));
|
|
266
273
|
}
|
|
267
274
|
static getAvailableAudioDevices() {
|
|
268
|
-
return
|
|
269
|
-
return navigator.mediaDevices.enumerateDevices().then((e) => e.filter((
|
|
275
|
+
return W(this, void 0, void 0, function* () {
|
|
276
|
+
return navigator.mediaDevices.enumerateDevices().then((e) => e.filter((i) => i.kind === "audioinput"));
|
|
270
277
|
});
|
|
271
278
|
}
|
|
272
279
|
destroy() {
|
|
273
280
|
this.applyOriginalOptionsIfNeeded(), super.destroy(), this.stopRecording(), this.stopMic();
|
|
274
281
|
}
|
|
275
282
|
applyOriginalOptionsIfNeeded() {
|
|
276
|
-
this.wavesurfer && this.originalOptions && (this.wavesurfer.
|
|
283
|
+
this.wavesurfer && this.originalOptions && (this.wavesurfer.setOptions(this.originalOptions), delete this.originalOptions);
|
|
277
284
|
}
|
|
278
285
|
}
|
|
279
|
-
const
|
|
280
|
-
const { waveSurfer:
|
|
281
|
-
Math.floor(
|
|
286
|
+
const q = ({ containerRef: n, options: e }) => {
|
|
287
|
+
const { waveSurfer: i } = P({ containerRef: n, options: e }), t = m(null), o = m(0), r = m(!1), s = m(!1), a = y(() => [
|
|
288
|
+
Math.floor(o.value % 36e5 / 6e4),
|
|
282
289
|
// minutes
|
|
283
|
-
Math.floor(
|
|
290
|
+
Math.floor(o.value % 6e4 / 1e3)
|
|
284
291
|
// seconds
|
|
285
|
-
].map((
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if ((a = i.value) != null && a.isRecording() || (h = i.value) != null && h.isPaused()) {
|
|
293
|
-
(m = i.value) == null || m.stopRecording(), r.value = !1, o.value = !0;
|
|
292
|
+
].map((c) => c < 10 ? "0" + c : c).join(":")), u = y(() => r.value || !s.value), l = () => {
|
|
293
|
+
t.value && t.value?.on("record-progress", (c) => {
|
|
294
|
+
o.value = c;
|
|
295
|
+
});
|
|
296
|
+
}, d = () => {
|
|
297
|
+
if (t.value?.isRecording() || t.value?.isPaused()) {
|
|
298
|
+
t.value?.stopRecording(), r.value = !1, s.value = !0;
|
|
294
299
|
return;
|
|
295
300
|
}
|
|
296
|
-
|
|
297
|
-
},
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
h = M, a(h);
|
|
301
|
+
t.value?.startRecording(), r.value = !0, s.value = !1, l();
|
|
302
|
+
}, f = () => new Promise((c) => {
|
|
303
|
+
let v;
|
|
304
|
+
(t.value?.isRecording() || t.value?.isPaused()) && (t.value?.stopRecording(), r.value = !1, s.value = !1), t.value?.on("record-end", (h) => {
|
|
305
|
+
v = h, c(v);
|
|
302
306
|
});
|
|
303
|
-
}),
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
(h = i.value) == null || h.resumeRecording(), r.value = !0, o.value = !1;
|
|
307
|
+
}), g = () => {
|
|
308
|
+
if (t.value?.isPaused()) {
|
|
309
|
+
t.value?.resumeRecording(), r.value = !0, s.value = !1;
|
|
307
310
|
return;
|
|
308
311
|
}
|
|
309
|
-
r.value = !1,
|
|
312
|
+
r.value = !1, s.value = !0, t.value?.pauseRecording();
|
|
310
313
|
};
|
|
311
|
-
return
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
a && (i.value = a);
|
|
314
|
+
return w(() => {
|
|
315
|
+
const c = i.value?.registerPlugin(R.create({ renderRecordedAudio: !1 }));
|
|
316
|
+
c && (t.value = c);
|
|
315
317
|
}), {
|
|
316
|
-
waveSurfer:
|
|
317
|
-
waveSurferRecorder:
|
|
318
|
-
currentTime:
|
|
319
|
-
startRecording:
|
|
320
|
-
stopRecording:
|
|
321
|
-
pauseRecording:
|
|
318
|
+
waveSurfer: i,
|
|
319
|
+
waveSurferRecorder: t,
|
|
320
|
+
currentTime: a,
|
|
321
|
+
startRecording: d,
|
|
322
|
+
stopRecording: f,
|
|
323
|
+
pauseRecording: g,
|
|
322
324
|
isRecording: r,
|
|
323
|
-
isPaused:
|
|
324
|
-
isPauseResume:
|
|
325
|
+
isPaused: s,
|
|
326
|
+
isPauseResume: u
|
|
325
327
|
};
|
|
326
328
|
};
|
|
327
329
|
export {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
330
|
+
U as WaveSurferPlayer,
|
|
331
|
+
k as useWaveSurfer,
|
|
332
|
+
q as useWaveSurferRecorder
|
|
331
333
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PartialWaveSurferOptions } from '../types';
|
|
2
|
+
declare const _default: import('vue').DefineComponent<{
|
|
3
|
+
options: PartialWaveSurferOptions;
|
|
4
|
+
}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{
|
|
5
|
+
options: PartialWaveSurferOptions;
|
|
6
|
+
}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
7
|
+
export default _default;
|