wavesurfer-rails 0.1.2 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +1 -12
- data/lib/wavesurfer/rails/version.rb +1 -1
- data/vendor/assets/javascripts/plugin/wavesurfer.elan.min.js +3 -0
- data/vendor/assets/javascripts/plugin/wavesurfer.microphone.min.js +3 -0
- data/vendor/assets/javascripts/plugin/wavesurfer.minimap.min.js +3 -0
- data/vendor/assets/javascripts/plugin/wavesurfer.regions.min.js +3 -0
- data/vendor/assets/javascripts/plugin/wavesurfer.spectrogram.min.js +3 -0
- data/vendor/assets/javascripts/plugin/wavesurfer.timeline.min.js +3 -0
- data/vendor/assets/javascripts/wavesurfer-plugins.js +6 -6
- data/wavesurfer-rails.gemspec +1 -1
- metadata +9 -9
- data/vendor/assets/javascripts/ws-plugins/wavesurfer.elan.js +0 -252
- data/vendor/assets/javascripts/ws-plugins/wavesurfer.microphone.js +0 -173
- data/vendor/assets/javascripts/ws-plugins/wavesurfer.minimap.js +0 -213
- data/vendor/assets/javascripts/ws-plugins/wavesurfer.regions.js +0 -416
- data/vendor/assets/javascripts/ws-plugins/wavesurfer.spectrogram.js +0 -223
- data/vendor/assets/javascripts/ws-plugins/wavesurfer.timeline.js +0 -196
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b74bbc6d65775aabf442823f930e18e53de588d6
|
4
|
+
data.tar.gz: 0b37128b7e4449c97f6f908f1fc00aa979ea56b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3b595b4b60f5e34fe1a4d7be5ae30b96882ffafe5b7d693af0faab9ff2000c2be1ea7b459240b39e04ae063a81f544a614241fee1009212b029a672facc50e5
|
7
|
+
data.tar.gz: 19d618627f6e0a078d9dd08e767bd1dfa041027c69e10d6ff47dd271071c80f6e72e8becf127d958331bb1fd8105a2a953af408873f1284351743dd6dcd4c543
|
data/README.md
CHANGED
@@ -20,18 +20,7 @@ In `app/assets/javascripts/application.js` put the following:
|
|
20
20
|
//= require wavesurfer
|
21
21
|
```
|
22
22
|
|
23
|
-
If you want the wavesurfer plugins
|
24
|
-
|
25
|
-
```javascript
|
26
|
-
//= require ws-plugins/wavesurfer.elan.js
|
27
|
-
//= require ws-plugins/wavesurfer.microphone.js
|
28
|
-
//= require ws-plugins/wavesurfer.minimap.js
|
29
|
-
//= require ws-plugins/wavesurfer.regions.js
|
30
|
-
//= require ws-plugins/wavesurfer.spectrogram.js
|
31
|
-
//= require ws-plugins/wavesurfer.timeline.js
|
32
|
-
```
|
33
|
-
|
34
|
-
Or require them all at once:
|
23
|
+
If you want the wavesurfer plugins:
|
35
24
|
|
36
25
|
```javascript
|
37
26
|
//= require wavesurfer-plugins
|
@@ -0,0 +1,3 @@
|
|
1
|
+
/*! wavesurfer.js 1.0.43
|
2
|
+
* https://github.com/katspaugh/wavesurfer.js
|
3
|
+
* @license CC-BY-3.0 */"use strict";WaveSurfer.ELAN={Types:{ALIGNABLE_ANNOTATION:"ALIGNABLE_ANNOTATION",REF_ANNOTATION:"REF_ANNOTATION"},init:function(a){if(this.data=null,this.params=a,this.container="string"==typeof a.container?document.querySelector(a.container):a.container,!this.container)throw Error("No container for ELAN");this.bindClick(),a.url&&this.load(a.url)},load:function(a){var b=this;this.loadXML(a,function(a){b.data=b.parseElan(a),b.render(),b.fireEvent("ready",b.data)})},loadXML:function(a,b){var c=new XMLHttpRequest;c.open("GET",a,!0),c.responseType="document",c.send(),c.addEventListener("load",function(a){b&&b(a.target.responseXML)})},parseElan:function(a){var b=Array.prototype.forEach,c=Array.prototype.map,d={media:{},timeOrder:{},tiers:[],annotations:{},alignableAnnotations:[]},e=a.querySelector("HEADER"),f="milliseconds"==e.getAttribute("TIME_UNITS"),g=e.querySelector("MEDIA_DESCRIPTOR");d.media.url=g.getAttribute("MEDIA_URL"),d.media.type=g.getAttribute("MIME_TYPE");var h=a.querySelectorAll("TIME_ORDER TIME_SLOT"),i={};return b.call(h,function(a){var b=parseFloat(a.getAttribute("TIME_VALUE"));f&&(b=Math.round(100*b)/1e5),i[a.getAttribute("TIME_SLOT_ID")]=b}),d.tiers=c.call(a.querySelectorAll("TIER"),function(a){return{id:a.getAttribute("TIER_ID"),linguisticTypeRef:a.getAttribute("LINGUISTIC_TYPE_REF"),defaultLocale:a.getAttribute("DEFAULT_LOCALE"),annotations:c.call(a.querySelectorAll("REF_ANNOTATION, ALIGNABLE_ANNOTATION"),function(a){var b={type:a.nodeName,id:a.getAttribute("ANNOTATION_ID"),ref:a.getAttribute("ANNOTATION_REF"),value:a.querySelector("ANNOTATION_VALUE").textContent.trim()};return this.Types.ALIGNABLE_ANNOTATION==b.type&&(b.start=i[a.getAttribute("TIME_SLOT_REF1")],b.end=i[a.getAttribute("TIME_SLOT_REF2")],d.alignableAnnotations.push(b)),d.annotations[b.id]=b,b},this)}},this),d.tiers.forEach(function(a){a.annotations.forEach(function(a){null!=a.ref&&(a.reference=d.annotations[a.ref])},this)},this),d.alignableAnnotations.sort(function(a,b){var c=a.start-b.start;return 0==c&&(c=b.end-a.end),c}),d.length=d.alignableAnnotations.length,d},render:function(){var a=this.data.tiers;this.params.tiers&&(a=a.filter(function(a){return a.id in this.params.tiers},this));var b={},c={};a.forEach(function(a,d){a.annotations.forEach(function(a){a.reference&&a.reference.type==this.Types.ALIGNABLE_ANNOTATION&&(a.reference.id in b||(b[a.ref]={}),b[a.ref][d]=a,c[d]=!0)},this)},this),c=Object.keys(c).sort(),this.renderedAlignable=this.data.alignableAnnotations.filter(function(a){return b[a.id]});var d=document.createElement("table");d.className="wavesurfer-annotations";var e=document.createElement("thead"),f=document.createElement("tr");e.appendChild(f),d.appendChild(e);var g=document.createElement("th");g.textContent="Time",g.className="wavesurfer-time",f.appendChild(g),c.forEach(function(b){var c=a[b],d=document.createElement("th");d.className="wavesurfer-tier-"+c.id,d.textContent=c.id,d.style.width=this.params.tiers[c.id],f.appendChild(d)},this);var h=document.createElement("tbody");d.appendChild(h),this.renderedAlignable.forEach(function(d){var e=document.createElement("tr");e.id="wavesurfer-alignable-"+d.id,h.appendChild(e);var f=document.createElement("td");f.className="wavesurfer-time",f.textContent=d.start.toFixed(1)+"–"+d.end.toFixed(1),e.appendChild(f);var g=b[d.id];c.forEach(function(b){var c=a[b],f=document.createElement("td"),h=g[b];h&&(f.id="wavesurfer-annotation-"+h.id,f.dataset.ref=d.id,f.dataset.start=d.start,f.dataset.end=d.end,f.textContent=h.value),f.className="wavesurfer-tier-"+c.id,e.appendChild(f)},this)},this),this.container.innerHTML="",this.container.appendChild(d)},bindClick:function(){var a=this;this.container.addEventListener("click",function(b){var c=b.target.dataset.ref;if(null!=c){var d=a.data.annotations[c];d&&a.fireEvent("select",d.start,d.end)}})},getRenderedAnnotation:function(a){var b;return this.renderedAlignable.some(function(c){return c.start<=a&&c.end>=a?(b=c,!0):!1}),b},getAnnotationNode:function(a){return document.getElementById("wavesurfer-alignable-"+a.id)}},WaveSurfer.util.extend(WaveSurfer.ELAN,WaveSurfer.Observer);
|
@@ -0,0 +1,3 @@
|
|
1
|
+
/*! wavesurfer.js 1.0.43
|
2
|
+
* https://github.com/katspaugh/wavesurfer.js
|
3
|
+
* @license CC-BY-3.0 */!function(a,b){"function"==typeof define&&define.amd?define(["wavesurfer"],b):a.WaveSurfer.Microphone=b(a.WaveSurfer)}(this,function(a){"use strict";return a.Microphone={init:function(a){this.params=a;this.wavesurfer=a.wavesurfer;if(!this.wavesurfer)throw new Error("No WaveSurfer instance provided");this.active=!1,this.paused=!1,this.getUserMedia=(navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia).bind(navigator),this.bufferSize=this.params.bufferSize||4096,this.numberOfInputChannels=this.params.numberOfInputChannels||1,this.numberOfOutputChannels=this.params.numberOfOutputChannels||1,this.micContext=this.wavesurfer.backend.getAudioContext()},start:function(){this.getUserMedia({video:!1,audio:!0},this.gotStream.bind(this),this.deviceError.bind(this))},togglePlay:function(){this.active?(this.paused=!this.paused,this.paused?this.disconnect():this.connect()):this.start()},stop:function(){this.active&&(this.active=!1,this.stream&&this.stream.stop(),this.disconnect(),this.wavesurfer.empty())},connect:function(){void 0!==this.stream&&(this.mediaStreamSource=this.micContext.createMediaStreamSource(this.stream),this.levelChecker=this.micContext.createScriptProcessor(this.bufferSize,this.numberOfInputChannels,this.numberOfOutputChannels),this.mediaStreamSource.connect(this.levelChecker),this.levelChecker.connect(this.micContext.destination),this.levelChecker.onaudioprocess=this.reloadBuffer.bind(this))},disconnect:function(){void 0!==this.mediaStreamSource&&this.mediaStreamSource.disconnect(),void 0!==this.levelChecker&&this.levelChecker.disconnect()},reloadBuffer:function(a){this.paused||(this.wavesurfer.empty(),this.wavesurfer.loadDecodedBuffer(a.inputBuffer))},gotStream:function(a){this.stream=a,this.active=!0,this.connect(),this.fireEvent("deviceReady",a)},destroy:function(a){this.stop()},deviceError:function(a){this.fireEvent("deviceError",a)}},a.util.extend(a.Microphone,a.Observer),a.Microphone});
|
@@ -0,0 +1,3 @@
|
|
1
|
+
/*! wavesurfer.js 1.0.43
|
2
|
+
* https://github.com/katspaugh/wavesurfer.js
|
3
|
+
* @license CC-BY-3.0 */"use strict";WaveSurfer.Minimap=WaveSurfer.util.extend({},WaveSurfer.Drawer,WaveSurfer.Drawer.Canvas,{init:function(a,b){this.wavesurfer=a,this.container=this.wavesurfer.drawer.container,this.lastPos=this.wavesurfer.drawer.lastPos,this.params=a.util.extend({},this.wavesurfer.drawer.params,{showRegions:!1,showOverview:!1,overviewBorderColor:"green",overviewBorderSize:2},b,{scrollParent:!1,fillParent:!0}),this.width=0,this.height=this.params.height*this.params.pixelRatio,this.createWrapper(),this.createElements(),WaveSurfer.Regions&&this.params.showRegions&&this.regions(),this.bindWaveSurferEvents(),this.bindMinimapEvents()},regions:function(){var a=this;this.regions={},this.wavesurfer.on("region-created",function(b){a.regions[b.id]=b,a.renderRegions()}),this.wavesurfer.on("region-updated",function(b){a.regions[b.id]=b,a.renderRegions()}),this.wavesurfer.on("region-removed",function(b){delete a.regions[b.id],a.renderRegions()})},renderRegions:function(){for(var a=this,b=this.wrapper.querySelectorAll("region"),c=0;c<b.length;++c)this.wrapper.removeChild(b[c]);Object.keys(this.regions).forEach(function(b){var c=a.regions[b],d=a.width*((c.end-c.start)/a.wavesurfer.getDuration()),e=a.width*(c.start/a.wavesurfer.getDuration()),f=a.style(document.createElement("region"),{height:"inherit",backgroundColor:c.color,width:d+"px",left:e+"px",display:"block",position:"absolute"});f.classList.add(b),a.wrapper.appendChild(f)})},createElements:function(){WaveSurfer.Drawer.Canvas.createElements.call(this),this.params.showOverview&&(this.overviewRegion=this.style(document.createElement("overview"),{height:this.wrapper.offsetHeight-2*this.params.overviewBorderSize+"px",width:"0px",display:"block",position:"absolute",cursor:"move",border:this.params.overviewBorderSize+"px solid "+this.params.overviewBorderColor,zIndex:2,opacity:this.params.overviewOpacity}),this.wrapper.appendChild(this.overviewRegion))},bindWaveSurferEvents:function(){var a=this;this.wavesurfer.on("ready",this.render.bind(this)),this.wavesurfer.on("audioprocess",function(b){a.progress(a.wavesurfer.backend.getPlayedPercents())}),this.wavesurfer.on("seek",function(b){a.progress(a.wavesurfer.backend.getPlayedPercents())}),this.params.showOverview&&(this.wavesurfer.on("scroll",function(b){a.draggingOverview||a.moveOverviewRegion(b.target.scrollLeft/a.ratio)}),this.wavesurfer.drawer.wrapper.addEventListener("mouseover",function(b){a.draggingOverview&&(a.draggingOverview=!1)}));var b=0,c=function(){b!=a.wrapper.clientWidth&&(b=a.wrapper.clientWidth,a.render(),a.progress(a.wavesurfer.backend.getPlayedPercents()))};window.addEventListener("resize",c,!0),this.wavesurfer.on("destroy",function(){a.destroy.bind(this),window.removeEventListener("resize",c,!0)})},bindMinimapEvents:function(){var a=this,b=0,c=!0,d={clientX:0,clientY:0};this.on("click",function(a,b){c?(this.progress(b),this.wavesurfer.seekAndCenter(b)):c=!0}.bind(this)),this.params.showOverview&&(this.overviewRegion.addEventListener("mousedown",function(c){a.draggingOverview=!0,b=c.layerX,d.clientX=c.clientX,d.clientY=c.clientY}),this.wrapper.addEventListener("mousemove",function(c){a.draggingOverview&&a.moveOverviewRegion(c.clientX-a.container.getBoundingClientRect().left-b)}),this.wrapper.addEventListener("mouseup",function(b){d.clientX-b.clientX===0&&d.clientX-b.clientX===0?(c=!0,a.draggingOverview=!1):a.draggingOverview&&(c=!1,a.draggingOverview=!1)}))},render:function(){var a=this.getWidth(),b=this.wavesurfer.backend.getPeaks(a);this.drawPeaks(b,a),this.params.showOverview&&(this.ratio=this.wavesurfer.drawer.width/this.width,this.waveShowedWidth=this.wavesurfer.drawer.width/this.ratio,this.waveWidth=this.wavesurfer.drawer.width,this.overviewWidth=this.width/this.ratio,this.overviewPosition=0,this.overviewRegion.style.width=this.overviewWidth-2*this.params.overviewBorderSize+"px")},moveOverviewRegion:function(a){0>a?this.overviewPosition=0:a+this.overviewWidth<this.width?this.overviewPosition=a:this.overviewPosition=this.width-this.overviewWidth,this.overviewRegion.style.left=this.overviewPosition+"px",this.wavesurfer.drawer.wrapper.scrollLeft=this.overviewPosition*this.ratio}}),WaveSurfer.initMinimap=function(a){var b=Object.create(WaveSurfer.Minimap);return b.init(this,a),b};
|
@@ -0,0 +1,3 @@
|
|
1
|
+
/*! wavesurfer.js 1.0.43
|
2
|
+
* https://github.com/katspaugh/wavesurfer.js
|
3
|
+
* @license CC-BY-3.0 */"use strict";WaveSurfer.Regions={init:function(a){this.wavesurfer=a,this.wrapper=this.wavesurfer.drawer.wrapper,this.list={}},add:function(a){var b=Object.create(WaveSurfer.Region);return b.init(a,this.wavesurfer),this.list[b.id]=b,b.on("remove",function(){delete this.list[b.id]}.bind(this)),b},clear:function(){Object.keys(this.list).forEach(function(a){this.list[a].remove()},this)},enableDragSelection:function(a){var b,c,d,e=this;this.wrapper.addEventListener("mousedown",function(a){b=!0,c=e.wavesurfer.drawer.handleEvent(a),d=null}),this.wrapper.addEventListener("mouseup",function(a){b=!1,d&&(d.fireEvent("update-end",a),e.wavesurfer.fireEvent("region-update-end",d,a)),d=null}),this.wrapper.addEventListener("mousemove",function(f){if(b){d||(d=e.add(a||{}));var g=e.wavesurfer.getDuration(),h=e.wavesurfer.drawer.handleEvent(f);d.update({start:Math.min(h*g,c*g),end:Math.max(h*g,c*g)})}})}},WaveSurfer.Region={style:WaveSurfer.Drawer.style,init:function(a,b){this.wavesurfer=b,this.wrapper=b.drawer.wrapper,this.id=null==a.id?WaveSurfer.util.getId():a.id,this.start=Number(a.start)||0,this.end=null==a.end?this.start+4/this.wrapper.scrollWidth*this.wavesurfer.getDuration():Number(a.end),this.resize=void 0===a.resize?!0:Boolean(a.resize),this.drag=void 0===a.drag?!0:Boolean(a.drag),this.loop=Boolean(a.loop),this.color=a.color||"rgba(0, 0, 0, 0.1)",this.data=a.data||{},this.maxLength=a.maxLength,this.minLength=a.minLength,this.bindInOut(),this.render(),this.wavesurfer.fireEvent("region-created",this)},update:function(a){null!=a.start&&(this.start=Number(a.start)),null!=a.end&&(this.end=Number(a.end)),null!=a.loop&&(this.loop=Boolean(a.loop)),null!=a.color&&(this.color=a.color),null!=a.data&&(this.data=a.data),null!=a.resize&&(this.resize=Boolean(a.resize)),null!=a.drag&&(this.drag=Boolean(a.drag)),null!=a.maxLength&&(this.maxLength=Number(a.maxLength)),null!=a.minLength&&(this.minLength=Number(a.minLength)),this.updateRender(),this.fireEvent("update"),this.wavesurfer.fireEvent("region-updated",this)},remove:function(a){this.element&&(this.wrapper.removeChild(this.element),this.element=null,this.fireEvent("remove"),this.wavesurfer.fireEvent("region-removed",this))},play:function(){this.wavesurfer.play(this.start,this.end),this.fireEvent("play"),this.wavesurfer.fireEvent("region-play",this)},playLoop:function(){this.play(),this.once("out",this.playLoop.bind(this))},render:function(){var a=document.createElement("region");a.className="wavesurfer-region",a.title=this.formatTime(this.start,this.end),a.setAttribute("data-id",this.id);this.wrapper.scrollWidth;if(this.style(a,{position:"absolute",zIndex:2,height:"100%",top:"0px"}),this.resize){var b=a.appendChild(document.createElement("handle")),c=a.appendChild(document.createElement("handle"));b.className="wavesurfer-handle wavesurfer-handle-start",c.className="wavesurfer-handle wavesurfer-handle-end";var d={cursor:"col-resize",position:"absolute",left:"0px",top:"0px",width:"1%",maxWidth:"4px",height:"100%"};this.style(b,d),this.style(c,d),this.style(c,{left:"100%"})}this.element=this.wrapper.appendChild(a),this.updateRender(),this.bindEvents(a)},formatTime:function(a,b){return(a==b?[a]:[a,b]).map(function(a){return[Math.floor(a%3600/60),("00"+Math.floor(a%60)).slice(-2)].join(":")}).join("–")},updateRender:function(){var a=this.wavesurfer.getDuration(),b=this.wrapper.scrollWidth;this.start<0&&(this.start=0,this.end=this.end-this.start),this.end>a&&(this.end=a,this.start=a-(this.end-this.start)),null!=this.minLength&&(this.end=Math.max(this.start+this.minLength,this.end)),null!=this.maxLength&&(this.end=Math.min(this.start+this.maxLength,this.end)),this.style(this.element,{left:~~(this.start/a*b)+"px",width:~~((this.end-this.start)/a*b)+"px",backgroundColor:this.color,cursor:this.drag?"move":"default"}),this.element.title=this.formatTime(this.start,this.end)},bindInOut:function(){var a=this,b=function(){a.firedIn=!1,a.firedOut=!1},c=function(b){!a.firedIn&&a.start<=b&&a.end>b&&(a.firedIn=!0,a.fireEvent("in"),a.wavesurfer.fireEvent("region-in",a)),!a.firedOut&&a.firedIn&&a.end<=Math.round(100*b)/100&&(a.firedOut=!0,a.fireEvent("out"),a.wavesurfer.fireEvent("region-out",a))};this.wavesurfer.on("play",b),this.wavesurfer.backend.on("audioprocess",c),this.on("remove",function(){a.wavesurfer.un("play",b),a.wavesurfer.backend.un("audioprocess",c)}),this.on("out",function(){a.loop&&a.wavesurfer.play(a.start)})},bindEvents:function(){var a=this;this.element.addEventListener("mouseenter",function(b){a.fireEvent("mouseenter",b),a.wavesurfer.fireEvent("region-mouseenter",a,b)}),this.element.addEventListener("mouseleave",function(b){a.fireEvent("mouseleave",b),a.wavesurfer.fireEvent("region-mouseleave",a,b)}),this.element.addEventListener("click",function(b){b.preventDefault(),a.fireEvent("click",b),a.wavesurfer.fireEvent("region-click",a,b)}),this.element.addEventListener("dblclick",function(b){b.stopPropagation(),b.preventDefault(),a.fireEvent("dblclick",b),a.wavesurfer.fireEvent("region-dblclick",a,b)}),(this.drag||this.resize)&&function(){var b,c,d,e=a.wavesurfer.getDuration(),f=function(f){f.stopPropagation(),d=a.wavesurfer.drawer.handleEvent(f)*e,"handle"==f.target.tagName.toLowerCase()?c=f.target.classList.contains("wavesurfer-handle-start")?"start":"end":b=!0},g=function(d){(b||c)&&(b=!1,c=!1,d.stopPropagation(),d.preventDefault(),a.fireEvent("update-end",d),a.wavesurfer.fireEvent("region-update-end",a,d))},h=function(f){if(b||c){var g=a.wavesurfer.drawer.handleEvent(f)*e,h=g-d;d=g,a.drag&&b&&a.onDrag(h),a.resize&&c&&a.onResize(h,c)}};a.element.addEventListener("mousedown",f),a.wrapper.addEventListener("mousemove",h),document.body.addEventListener("mouseup",g),a.on("remove",function(){document.body.removeEventListener("mouseup",g),a.wrapper.removeEventListener("mousemove",h)}),a.wavesurfer.on("destroy",function(){document.body.removeEventListener("mouseup",g)})}()},onDrag:function(a){this.update({start:this.start+a,end:this.end+a})},onResize:function(a,b){"start"==b?this.update({start:Math.min(this.start+a,this.end),end:Math.max(this.start+a,this.end)}):this.update({start:Math.min(this.end+a,this.start),end:Math.max(this.end+a,this.start)})}},WaveSurfer.util.extend(WaveSurfer.Region,WaveSurfer.Observer),WaveSurfer.initRegions=function(){this.regions||(this.regions=Object.create(WaveSurfer.Regions),this.regions.init(this))},WaveSurfer.addRegion=function(a){return this.initRegions(),this.regions.add(a)},WaveSurfer.clearRegions=function(){this.regions&&this.regions.clear()},WaveSurfer.enableDragSelection=function(a){this.initRegions(),this.regions.enableDragSelection(a)};
|
@@ -0,0 +1,3 @@
|
|
1
|
+
/*! wavesurfer.js 1.0.43
|
2
|
+
* https://github.com/katspaugh/wavesurfer.js
|
3
|
+
* @license CC-BY-3.0 */"use strict";WaveSurfer.Spectrogram={init:function(a){this.params=a;var b=this.wavesurfer=a.wavesurfer;if(!this.wavesurfer)throw Error("No WaveSurfer instance provided");this.frequenciesDataUrl=a.frequenciesDataUrl;var c=this.drawer=this.wavesurfer.drawer;if(this.buffer=this.wavesurfer.backend.buffer,this.container="string"==typeof a.container?document.querySelector(a.container):a.container,!this.container)throw Error("No container for WaveSurfer spectrogram");this.width=c.width,this.pixelRatio=this.params.pixelRatio||b.params.pixelRatio,this.fftSamples=this.params.fftSamples||b.params.fftSamples||512,this.height=this.fftSamples/2,this.createWrapper(),this.createCanvas(),this.render(),b.drawer.wrapper.onscroll=this.updateScroll.bind(this),b.on("destroy",this.destroy.bind(this))},destroy:function(){this.unAll(),this.wrapper&&(this.wrapper.parentNode.removeChild(this.wrapper),this.wrapper=null)},createWrapper:function(){var a=this.container.querySelector("spectrogram");a&&this.container.removeChild(a);var b=this.wavesurfer.params;this.wrapper=this.container.appendChild(document.createElement("spectrogram")),this.drawer.style(this.wrapper,{display:"block",position:"relative",userSelect:"none",webkitUserSelect:"none",height:this.height+"px"}),(b.fillParent||b.scrollParent)&&this.drawer.style(this.wrapper,{width:"100%",overflowX:"hidden",overflowY:"hidden"});var c=this;this.wrapper.addEventListener("click",function(a){a.preventDefault();var b="offsetX"in a?a.offsetX:a.layerX;c.fireEvent("click",b/c.scrollWidth||0)})},createCanvas:function(){var a=this.canvas=this.wrapper.appendChild(document.createElement("canvas"));this.spectrCc=a.getContext("2d"),this.wavesurfer.drawer.style(a,{position:"absolute",zIndex:4})},render:function(){this.updateCanvasStyle(),this.frequenciesDataUrl?this.loadFrequenciesData(this.frequenciesDataUrl):this.getFrequencies(this.drawSpectrogram)},updateCanvasStyle:function(){var a=Math.round(this.width/this.pixelRatio)+"px";this.canvas.width=this.width,this.canvas.height=this.height,this.canvas.style.width=a},drawSpectrogram:function(a,b){for(var c=(b.spectrCc,b.wavesurfer.backend.getDuration(),b.height),d=b.resample(a),e=2/b.buffer.numberOfChannels,f=0;f<d.length;f++)for(var g=0;g<d[f].length;g++){var h=255-d[f][g];b.spectrCc.fillStyle="rgb("+h+", "+h+", "+h+")",b.spectrCc.fillRect(f,c-g*e,1,1*e)}},getFrequencies:function(a){var b=this.fftSamples,c=this.buffer,d=[],e=new window.OfflineAudioContext(1,c.length,c.sampleRate),f=e.createBufferSource(),g=e.createScriptProcessor(0,1,1),h=e.createAnalyser();h.fftSize=b,h.smoothingTimeConstant=this.width/c.duration<10?.75:.25,f.buffer=c,f.connect(h),h.connect(g),g.connect(e.destination),g.onaudioprocess=function(){var a=new Uint8Array(h.frequencyBinCount);h.getByteFrequencyData(a),d.push(a)},f.start(0),e.startRendering();var i=this;e.oncomplete=function(){a(d,i)}},loadFrequenciesData:function(a){var b=this,c=WaveSurfer.util.ajax({url:a});return c.on("success",function(a){b.drawSpectrogram(JSON.parse(a),b)}),c.on("error",function(a){b.fireEvent("error","XHR error: "+a.target.statusText)}),c},updateScroll:function(a){this.wrapper.scrollLeft=a.target.scrollLeft},resample:function(a,b){for(var b=this.width,c=[],d=1/a.length,e=1/b,f=0;b>f;f++){for(var g=new Array(a[0].length),h=0;h<a.length;h++){var i=h*d,j=i+d,k=f*e,l=k+e,m=k>=j||i>=l?0:Math.min(Math.max(j,k),Math.max(l,i))-Math.max(Math.min(j,k),Math.min(l,i));if(m>0)for(var n=0;n<a[0].length;n++)null==g[n]&&(g[n]=0),g[n]+=m/e*a[h][n]}for(var o=new Uint8Array(a[0].length),n=0;n<a[0].length;n++)o[n]=g[n];c.push(o)}return c}},WaveSurfer.util.extend(WaveSurfer.Spectrogram,WaveSurfer.Observer);
|
@@ -0,0 +1,3 @@
|
|
1
|
+
/*! wavesurfer.js 1.0.43
|
2
|
+
* https://github.com/katspaugh/wavesurfer.js
|
3
|
+
* @license CC-BY-3.0 */!function(a,b){"function"==typeof define&&define.amd?define(["wavesurfer"],b):a.WaveSurfer.Timeline=b(a.WaveSurfer)}(this,function(a){"use strict";return a.Timeline={init:function(a){this.params=a;var b=this.wavesurfer=a.wavesurfer;if(!this.wavesurfer)throw Error("No WaveSurfer intance provided");var c=this.drawer=this.wavesurfer.drawer;if(this.container="string"==typeof a.container?document.querySelector(a.container):a.container,!this.container)throw Error("No container for WaveSurfer timeline");this.width=c.width,this.height=this.params.height||20,this.notchPercentHeight=this.params.notchPercentHeight||90,this.primaryColor=this.params.primaryColor||"#000",this.secondaryColor=this.params.secondaryColor||"#c0c0c0",this.primaryFontColor=this.params.primaryFontColor||"#000",this.secondaryFontColor=this.params.secondaryFontColor||"#000",this.fontFamily=this.params.fontFamily||"Arial",this.fontSize=this.params.fontSize||10,this.createWrapper(),this.createCanvas(),this.render(),b.drawer.wrapper.onscroll=this.updateScroll.bind(this),b.on("redraw",this.render.bind(this)),b.on("destroy",this.destroy.bind(this))},destroy:function(){this.unAll(),this.wrapper&&this.wrapper.parentNode&&(this.wrapper.parentNode.removeChild(this.wrapper),this.wrapper=null)},createWrapper:function(){var a=this.container.querySelector("timeline");a&&this.container.removeChild(a);var b=this.wavesurfer.params;this.wrapper=this.container.appendChild(document.createElement("timeline")),this.drawer.style(this.wrapper,{display:"block",position:"relative",userSelect:"none",webkitUserSelect:"none",height:this.height+"px"}),(b.fillParent||b.scrollParent)&&this.drawer.style(this.wrapper,{width:"100%",overflowX:"hidden",overflowY:"hidden"});var c=this;this.wrapper.addEventListener("click",function(a){a.preventDefault();var b="offsetX"in a?a.offsetX:a.layerX;c.fireEvent("click",b/c.wrapper.scrollWidth||0)})},createCanvas:function(){var a=this.canvas=this.wrapper.appendChild(document.createElement("canvas"));this.timeCc=a.getContext("2d"),this.wavesurfer.drawer.style(a,{position:"absolute",zIndex:4})},render:function(){this.updateCanvasStyle(),this.drawTimeCanvas()},updateCanvasStyle:function(){var a=this.drawer.wrapper.scrollWidth;this.canvas.width=a*this.wavesurfer.params.pixelRatio,this.canvas.height=this.height*this.wavesurfer.params.pixelRatio,this.canvas.style.width=a+"px",this.canvas.style.height=this.height+"px"},drawTimeCanvas:function(){var a=this.wavesurfer.backend,b=this.wavesurfer.params,c=a.getDuration();if(b.fillParent&&!b.scrollParent)var d=this.drawer.getWidth();else d=this.drawer.wrapper.scrollWidth*b.pixelRatio;var e=d/c;if(c>0){var f=0,g=0,h=parseInt(c,10)+1,i=function(a){if(a/60>1){var b=parseInt(a/60),a=parseInt(a%60);return a=10>a?"0"+a:a,""+b+":"+a}return a};if(1*e>=25)var j=1,k=10,l=5;else if(5*e>=25)var j=5,k=6,l=2;else if(15*e>=25)var j=15,k=4,l=2;else var j=60,k=4,l=2;for(var m=this.height-4,n=this.height*(this.notchPercentHeight/100)-4,o=this.fontSize*b.pixelRatio,p=0;h/j>p;p++)p%k==0?(this.timeCc.fillStyle=this.primaryColor,this.timeCc.fillRect(f,0,1,m),this.timeCc.font=o+"px "+this.fontFamily,this.timeCc.fillStyle=this.primaryFontColor,this.timeCc.fillText(i(g),f+5,m)):p%l==0?(this.timeCc.fillStyle=this.secondaryColor,this.timeCc.fillRect(f,0,1,m),this.timeCc.font=o+"px "+this.fontFamily,this.timeCc.fillStyle=this.secondaryFontColor,this.timeCc.fillText(i(g),f+5,m)):(this.timeCc.fillStyle=this.secondaryColor,this.timeCc.fillRect(f,0,1,n)),g+=j,f+=e*j}},updateScroll:function(){this.wrapper.scrollLeft=this.drawer.wrapper.scrollLeft}},a.util.extend(a.Timeline,a.Observer),a.Timeline});
|
@@ -1,6 +1,6 @@
|
|
1
|
-
//= require
|
2
|
-
//= require
|
3
|
-
//= require
|
4
|
-
//= require
|
5
|
-
//= require
|
6
|
-
//= require
|
1
|
+
//= require plugin/wavesurfer.elan.min.js
|
2
|
+
//= require plugin/wavesurfer.microphone.min.js
|
3
|
+
//= require plugin/wavesurfer.minimap.min.js
|
4
|
+
//= require plugin/wavesurfer.regions.min.js
|
5
|
+
//= require plugin/wavesurfer.spectrogram.min.js
|
6
|
+
//= require plugin/wavesurfer.timeline.min.js
|
data/wavesurfer-rails.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["mdaugherty6@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{http://wavesurfer-js.org/}
|
13
|
-
spec.description = %q{Wavesurfer.js for the rails asset pipeline.
|
13
|
+
spec.description = %q{Wavesurfer.js for the rails asset pipeline.}
|
14
14
|
spec.homepage = "http://gdclifford.info/"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wavesurfer-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Daugherty
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
description: Wavesurfer.js for the rails asset pipeline.
|
41
|
+
description: Wavesurfer.js for the rails asset pipeline.
|
42
42
|
email:
|
43
43
|
- mdaugherty6@gmail.com
|
44
44
|
executables: []
|
@@ -55,15 +55,15 @@ files:
|
|
55
55
|
- lib/wavesurfer/rails.rb
|
56
56
|
- lib/wavesurfer/rails/engine.rb
|
57
57
|
- lib/wavesurfer/rails/version.rb
|
58
|
+
- vendor/assets/javascripts/plugin/wavesurfer.elan.min.js
|
59
|
+
- vendor/assets/javascripts/plugin/wavesurfer.microphone.min.js
|
60
|
+
- vendor/assets/javascripts/plugin/wavesurfer.minimap.min.js
|
61
|
+
- vendor/assets/javascripts/plugin/wavesurfer.regions.min.js
|
62
|
+
- vendor/assets/javascripts/plugin/wavesurfer.spectrogram.min.js
|
63
|
+
- vendor/assets/javascripts/plugin/wavesurfer.timeline.min.js
|
58
64
|
- vendor/assets/javascripts/wavesurfer-plugins.js
|
59
65
|
- vendor/assets/javascripts/wavesurfer.js
|
60
66
|
- vendor/assets/javascripts/wavesurfer.min.js
|
61
|
-
- vendor/assets/javascripts/ws-plugins/wavesurfer.elan.js
|
62
|
-
- vendor/assets/javascripts/ws-plugins/wavesurfer.microphone.js
|
63
|
-
- vendor/assets/javascripts/ws-plugins/wavesurfer.minimap.js
|
64
|
-
- vendor/assets/javascripts/ws-plugins/wavesurfer.regions.js
|
65
|
-
- vendor/assets/javascripts/ws-plugins/wavesurfer.spectrogram.js
|
66
|
-
- vendor/assets/javascripts/ws-plugins/wavesurfer.timeline.js
|
67
67
|
- wavesurfer-rails.gemspec
|
68
68
|
homepage: http://gdclifford.info/
|
69
69
|
licenses:
|
@@ -1,252 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
WaveSurfer.ELAN = {
|
4
|
-
Types: {
|
5
|
-
ALIGNABLE_ANNOTATION: 'ALIGNABLE_ANNOTATION',
|
6
|
-
REF_ANNOTATION: 'REF_ANNOTATION'
|
7
|
-
},
|
8
|
-
|
9
|
-
init: function (params) {
|
10
|
-
this.data = null;
|
11
|
-
this.params = params;
|
12
|
-
this.container = 'string' == typeof params.container ?
|
13
|
-
document.querySelector(params.container) : params.container;
|
14
|
-
|
15
|
-
if (!this.container) {
|
16
|
-
throw Error('No container for ELAN');
|
17
|
-
}
|
18
|
-
|
19
|
-
this.bindClick();
|
20
|
-
|
21
|
-
if (params.url) {
|
22
|
-
this.load(params.url);
|
23
|
-
}
|
24
|
-
},
|
25
|
-
|
26
|
-
load: function (url) {
|
27
|
-
var my = this;
|
28
|
-
this.loadXML(url, function (xml) {
|
29
|
-
my.data = my.parseElan(xml);
|
30
|
-
my.render();
|
31
|
-
my.fireEvent('ready', my.data);
|
32
|
-
});
|
33
|
-
},
|
34
|
-
|
35
|
-
loadXML: function (url, callback) {
|
36
|
-
var xhr = new XMLHttpRequest();
|
37
|
-
xhr.open('GET', url, true);
|
38
|
-
xhr.responseType = 'document';
|
39
|
-
xhr.send();
|
40
|
-
xhr.addEventListener('load', function (e) {
|
41
|
-
callback && callback(e.target.responseXML);
|
42
|
-
});
|
43
|
-
},
|
44
|
-
|
45
|
-
parseElan: function (xml) {
|
46
|
-
var _forEach = Array.prototype.forEach;
|
47
|
-
var _map = Array.prototype.map;
|
48
|
-
|
49
|
-
var data = {
|
50
|
-
media: {},
|
51
|
-
timeOrder: {},
|
52
|
-
tiers: [],
|
53
|
-
annotations: {},
|
54
|
-
alignableAnnotations: []
|
55
|
-
};
|
56
|
-
|
57
|
-
var header = xml.querySelector('HEADER');
|
58
|
-
var inMilliseconds = header.getAttribute('TIME_UNITS') == 'milliseconds';
|
59
|
-
var media = header.querySelector('MEDIA_DESCRIPTOR');
|
60
|
-
data.media.url = media.getAttribute('MEDIA_URL');
|
61
|
-
data.media.type = media.getAttribute('MIME_TYPE');
|
62
|
-
|
63
|
-
var timeSlots = xml.querySelectorAll('TIME_ORDER TIME_SLOT');
|
64
|
-
var timeOrder = {};
|
65
|
-
_forEach.call(timeSlots, function (slot) {
|
66
|
-
var value = parseFloat(slot.getAttribute('TIME_VALUE'));
|
67
|
-
// If in milliseconds, convert to seconds with rounding
|
68
|
-
if (inMilliseconds) {
|
69
|
-
value = Math.round(value * 1e2) / 1e5;
|
70
|
-
}
|
71
|
-
timeOrder[slot.getAttribute('TIME_SLOT_ID')] = value;
|
72
|
-
});
|
73
|
-
|
74
|
-
data.tiers = _map.call(xml.querySelectorAll('TIER'), function (tier) {
|
75
|
-
return {
|
76
|
-
id: tier.getAttribute('TIER_ID'),
|
77
|
-
linguisticTypeRef: tier.getAttribute('LINGUISTIC_TYPE_REF'),
|
78
|
-
defaultLocale: tier.getAttribute('DEFAULT_LOCALE'),
|
79
|
-
annotations: _map.call(
|
80
|
-
tier.querySelectorAll('REF_ANNOTATION, ALIGNABLE_ANNOTATION'),
|
81
|
-
function (node) {
|
82
|
-
var annot = {
|
83
|
-
type: node.nodeName,
|
84
|
-
id: node.getAttribute('ANNOTATION_ID'),
|
85
|
-
ref: node.getAttribute('ANNOTATION_REF'),
|
86
|
-
value: node.querySelector('ANNOTATION_VALUE')
|
87
|
-
.textContent.trim()
|
88
|
-
};
|
89
|
-
|
90
|
-
if (this.Types.ALIGNABLE_ANNOTATION == annot.type) {
|
91
|
-
// Add start & end to alignable annotation
|
92
|
-
annot.start = timeOrder[node.getAttribute('TIME_SLOT_REF1')];
|
93
|
-
annot.end = timeOrder[node.getAttribute('TIME_SLOT_REF2')];
|
94
|
-
|
95
|
-
// Add to the list of alignable annotations
|
96
|
-
data.alignableAnnotations.push(annot);
|
97
|
-
}
|
98
|
-
|
99
|
-
// Additionally, put into the flat map of all annotations
|
100
|
-
data.annotations[annot.id] = annot;
|
101
|
-
|
102
|
-
return annot;
|
103
|
-
}, this
|
104
|
-
)
|
105
|
-
};
|
106
|
-
}, this);
|
107
|
-
|
108
|
-
// Create JavaScript references between annotations
|
109
|
-
data.tiers.forEach(function (tier) {
|
110
|
-
tier.annotations.forEach(function (annot) {
|
111
|
-
if (null != annot.ref) {
|
112
|
-
annot.reference = data.annotations[annot.ref];
|
113
|
-
}
|
114
|
-
}, this);
|
115
|
-
}, this);
|
116
|
-
|
117
|
-
// Sort alignable annotations by start & end
|
118
|
-
data.alignableAnnotations.sort(function (a, b) {
|
119
|
-
var d = a.start - b.start;
|
120
|
-
if (d == 0) {
|
121
|
-
d = b.end - a.end;
|
122
|
-
}
|
123
|
-
return d;
|
124
|
-
});
|
125
|
-
|
126
|
-
data.length = data.alignableAnnotations.length;
|
127
|
-
|
128
|
-
return data;
|
129
|
-
},
|
130
|
-
|
131
|
-
render: function () {
|
132
|
-
// apply tiers filter
|
133
|
-
var tiers = this.data.tiers;
|
134
|
-
if (this.params.tiers) {
|
135
|
-
tiers = tiers.filter(function (tier) {
|
136
|
-
return tier.id in this.params.tiers;
|
137
|
-
}, this);
|
138
|
-
}
|
139
|
-
|
140
|
-
// denormalize references to alignable annotations
|
141
|
-
var backRefs = {};
|
142
|
-
var indeces = {};
|
143
|
-
tiers.forEach(function (tier, index) {
|
144
|
-
tier.annotations.forEach(function (annot) {
|
145
|
-
if (annot.reference &&
|
146
|
-
annot.reference.type == this.Types.ALIGNABLE_ANNOTATION) {
|
147
|
-
if (!(annot.reference.id in backRefs)) {
|
148
|
-
backRefs[annot.ref] = {};
|
149
|
-
}
|
150
|
-
backRefs[annot.ref][index] = annot;
|
151
|
-
indeces[index] = true;
|
152
|
-
}
|
153
|
-
}, this);
|
154
|
-
}, this);
|
155
|
-
indeces = Object.keys(indeces).sort();
|
156
|
-
|
157
|
-
this.renderedAlignable = this.data.alignableAnnotations.filter(
|
158
|
-
function (alignable) {
|
159
|
-
return backRefs[alignable.id];
|
160
|
-
}
|
161
|
-
);
|
162
|
-
|
163
|
-
// table
|
164
|
-
var table = document.createElement('table');
|
165
|
-
table.className = 'wavesurfer-annotations';
|
166
|
-
|
167
|
-
// head
|
168
|
-
var thead = document.createElement('thead');
|
169
|
-
var headRow = document.createElement('tr');
|
170
|
-
thead.appendChild(headRow);
|
171
|
-
table.appendChild(thead);
|
172
|
-
var th = document.createElement('th');
|
173
|
-
th.textContent = 'Time';
|
174
|
-
th.className = 'wavesurfer-time';
|
175
|
-
headRow.appendChild(th);
|
176
|
-
indeces.forEach(function (index) {
|
177
|
-
var tier = tiers[index];
|
178
|
-
var th = document.createElement('th');
|
179
|
-
th.className = 'wavesurfer-tier-' + tier.id;
|
180
|
-
th.textContent = tier.id;
|
181
|
-
th.style.width = this.params.tiers[tier.id];
|
182
|
-
headRow.appendChild(th);
|
183
|
-
}, this);
|
184
|
-
|
185
|
-
// body
|
186
|
-
var tbody = document.createElement('tbody');
|
187
|
-
table.appendChild(tbody);
|
188
|
-
this.renderedAlignable.forEach(function (alignable) {
|
189
|
-
var row = document.createElement('tr');
|
190
|
-
row.id = 'wavesurfer-alignable-' + alignable.id;
|
191
|
-
tbody.appendChild(row);
|
192
|
-
|
193
|
-
var td = document.createElement('td');
|
194
|
-
td.className = 'wavesurfer-time';
|
195
|
-
td.textContent = alignable.start.toFixed(1) + '–' +
|
196
|
-
alignable.end.toFixed(1);
|
197
|
-
row.appendChild(td);
|
198
|
-
|
199
|
-
var backRef = backRefs[alignable.id];
|
200
|
-
indeces.forEach(function (index) {
|
201
|
-
var tier = tiers[index];
|
202
|
-
var td = document.createElement('td');
|
203
|
-
var annotation = backRef[index];
|
204
|
-
if (annotation) {
|
205
|
-
td.id = 'wavesurfer-annotation-' + annotation.id;
|
206
|
-
td.dataset.ref = alignable.id;
|
207
|
-
td.dataset.start = alignable.start;
|
208
|
-
td.dataset.end = alignable.end;
|
209
|
-
td.textContent = annotation.value;
|
210
|
-
}
|
211
|
-
td.className = 'wavesurfer-tier-' + tier.id;
|
212
|
-
row.appendChild(td);
|
213
|
-
}, this);
|
214
|
-
}, this);
|
215
|
-
|
216
|
-
this.container.innerHTML = '';
|
217
|
-
this.container.appendChild(table);
|
218
|
-
},
|
219
|
-
|
220
|
-
bindClick: function () {
|
221
|
-
var my = this;
|
222
|
-
this.container.addEventListener('click', function (e) {
|
223
|
-
var ref = e.target.dataset.ref;
|
224
|
-
if (null != ref) {
|
225
|
-
var annot = my.data.annotations[ref];
|
226
|
-
if (annot) {
|
227
|
-
my.fireEvent('select', annot.start, annot.end);
|
228
|
-
}
|
229
|
-
}
|
230
|
-
});
|
231
|
-
},
|
232
|
-
|
233
|
-
getRenderedAnnotation: function (time) {
|
234
|
-
var result;
|
235
|
-
this.renderedAlignable.some(function (annotation) {
|
236
|
-
if (annotation.start <= time && annotation.end >= time) {
|
237
|
-
result = annotation;
|
238
|
-
return true;
|
239
|
-
}
|
240
|
-
return false;
|
241
|
-
});
|
242
|
-
return result;
|
243
|
-
},
|
244
|
-
|
245
|
-
getAnnotationNode: function (annotation) {
|
246
|
-
return document.getElementById(
|
247
|
-
'wavesurfer-alignable-' + annotation.id
|
248
|
-
);
|
249
|
-
}
|
250
|
-
};
|
251
|
-
|
252
|
-
WaveSurfer.util.extend(WaveSurfer.ELAN, WaveSurfer.Observer);
|
@@ -1,173 +0,0 @@
|
|
1
|
-
(function (root, factory) {
|
2
|
-
if (typeof define === 'function' && define.amd) {
|
3
|
-
define(['wavesurfer'], factory);
|
4
|
-
} else {
|
5
|
-
root.WaveSurfer.Microphone = factory(root.WaveSurfer);
|
6
|
-
}
|
7
|
-
}(this, function (WaveSurfer) {
|
8
|
-
'use strict';
|
9
|
-
|
10
|
-
WaveSurfer.Microphone = {
|
11
|
-
init: function (params) {
|
12
|
-
this.params = params;
|
13
|
-
|
14
|
-
var wavesurfer = this.wavesurfer = params.wavesurfer;
|
15
|
-
|
16
|
-
if (!this.wavesurfer) {
|
17
|
-
throw new Error('No WaveSurfer instance provided');
|
18
|
-
}
|
19
|
-
|
20
|
-
this.active = false;
|
21
|
-
this.paused = false;
|
22
|
-
|
23
|
-
// cross-browser getUserMedia
|
24
|
-
this.getUserMedia = (
|
25
|
-
navigator.getUserMedia ||
|
26
|
-
navigator.webkitGetUserMedia ||
|
27
|
-
navigator.mozGetUserMedia ||
|
28
|
-
navigator.msGetUserMedia
|
29
|
-
).bind(navigator);
|
30
|
-
|
31
|
-
// The buffer size in units of sample-frames.
|
32
|
-
// If specified, the bufferSize must be one of the following values:
|
33
|
-
// 256, 512, 1024, 2048, 4096, 8192, 16384. Defaults to 4096.
|
34
|
-
this.bufferSize = this.params.bufferSize || 4096;
|
35
|
-
|
36
|
-
// Integer specifying the number of channels for this node's input,
|
37
|
-
// defaults to 1. Values of up to 32 are supported.
|
38
|
-
this.numberOfInputChannels = this.params.numberOfInputChannels || 1;
|
39
|
-
|
40
|
-
// Integer specifying the number of channels for this node's output,
|
41
|
-
// defaults to 1. Values of up to 32 are supported.
|
42
|
-
this.numberOfOutputChannels = this.params.numberOfOutputChannels || 1;
|
43
|
-
|
44
|
-
// wavesurfer's AudioContext where we'll route the mic signal to
|
45
|
-
this.micContext = this.wavesurfer.backend.getAudioContext();
|
46
|
-
},
|
47
|
-
|
48
|
-
/**
|
49
|
-
* Allow user to select audio input device, eg. microphone, and
|
50
|
-
* start the visualization.
|
51
|
-
*/
|
52
|
-
start: function() {
|
53
|
-
this.getUserMedia({
|
54
|
-
video: false,
|
55
|
-
audio: true
|
56
|
-
},
|
57
|
-
this.gotStream.bind(this),
|
58
|
-
this.deviceError.bind(this));
|
59
|
-
},
|
60
|
-
|
61
|
-
/**
|
62
|
-
* Pause/resume visualization.
|
63
|
-
*/
|
64
|
-
togglePlay: function() {
|
65
|
-
if (!this.active) {
|
66
|
-
// start it first
|
67
|
-
this.start();
|
68
|
-
} else {
|
69
|
-
// toggle paused
|
70
|
-
this.paused = !this.paused;
|
71
|
-
|
72
|
-
if (this.paused) {
|
73
|
-
// disconnect sources so they can be used elsewhere
|
74
|
-
// (eg. during audio playback)
|
75
|
-
this.disconnect();
|
76
|
-
} else {
|
77
|
-
// resume visualization
|
78
|
-
this.connect();
|
79
|
-
}
|
80
|
-
}
|
81
|
-
},
|
82
|
-
|
83
|
-
/**
|
84
|
-
* Stop the microphone and visualization.
|
85
|
-
*/
|
86
|
-
stop: function() {
|
87
|
-
if (this.active) {
|
88
|
-
this.active = false;
|
89
|
-
|
90
|
-
if (this.stream) {
|
91
|
-
this.stream.stop();
|
92
|
-
}
|
93
|
-
this.disconnect();
|
94
|
-
this.wavesurfer.empty();
|
95
|
-
}
|
96
|
-
},
|
97
|
-
|
98
|
-
/**
|
99
|
-
* Connect the media sources that feed the visualization.
|
100
|
-
*/
|
101
|
-
connect: function() {
|
102
|
-
if (this.stream !== undefined) {
|
103
|
-
// Create an AudioNode from the stream.
|
104
|
-
this.mediaStreamSource = this.micContext.createMediaStreamSource(this.stream);
|
105
|
-
|
106
|
-
this.levelChecker = this.micContext.createScriptProcessor(
|
107
|
-
this.bufferSize, this.numberOfInputChannels, this.numberOfOutputChannels);
|
108
|
-
this.mediaStreamSource.connect(this.levelChecker);
|
109
|
-
|
110
|
-
this.levelChecker.connect(this.micContext.destination);
|
111
|
-
this.levelChecker.onaudioprocess = this.reloadBuffer.bind(this);
|
112
|
-
}
|
113
|
-
},
|
114
|
-
|
115
|
-
/**
|
116
|
-
* Disconnect the media sources that feed the visualization.
|
117
|
-
*/
|
118
|
-
disconnect: function() {
|
119
|
-
if (this.mediaStreamSource !== undefined) {
|
120
|
-
this.mediaStreamSource.disconnect();
|
121
|
-
}
|
122
|
-
|
123
|
-
if (this.levelChecker !== undefined) {
|
124
|
-
this.levelChecker.disconnect();
|
125
|
-
}
|
126
|
-
},
|
127
|
-
|
128
|
-
/**
|
129
|
-
* Redraw the waveform.
|
130
|
-
*/
|
131
|
-
reloadBuffer: function(event) {
|
132
|
-
if (!this.paused) {
|
133
|
-
this.wavesurfer.empty();
|
134
|
-
this.wavesurfer.loadDecodedBuffer(event.inputBuffer);
|
135
|
-
}
|
136
|
-
},
|
137
|
-
|
138
|
-
/**
|
139
|
-
* Audio input device is ready.
|
140
|
-
*
|
141
|
-
* @param {LocalMediaStream} stream: the microphone's media stream.
|
142
|
-
*/
|
143
|
-
gotStream: function(stream) {
|
144
|
-
this.stream = stream;
|
145
|
-
this.active = true;
|
146
|
-
|
147
|
-
this.connect();
|
148
|
-
|
149
|
-
// notify listeners
|
150
|
-
this.fireEvent('deviceReady', stream);
|
151
|
-
},
|
152
|
-
|
153
|
-
/**
|
154
|
-
* Destroy the microphone plugin.
|
155
|
-
*/
|
156
|
-
destroy: function(event) {
|
157
|
-
this.stop();
|
158
|
-
},
|
159
|
-
|
160
|
-
/**
|
161
|
-
* Device error callback.
|
162
|
-
*/
|
163
|
-
deviceError: function(code) {
|
164
|
-
// notify listeners
|
165
|
-
this.fireEvent('deviceError', code);
|
166
|
-
}
|
167
|
-
|
168
|
-
};
|
169
|
-
|
170
|
-
WaveSurfer.util.extend(WaveSurfer.Microphone, WaveSurfer.Observer);
|
171
|
-
|
172
|
-
return WaveSurfer.Microphone;
|
173
|
-
}));
|