app.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. 'use strict';
  2. var wavesurfer;
  3. // Init & load
  4. document.addEventListener('DOMContentLoaded', function () {
  5. var pluginOptions = {
  6. minimap: {
  7. waveColor : '#777',
  8. progressColor : '#222',
  9. height: 30
  10. },
  11. timeline: {
  12. container: '#wave-timeline'
  13. },
  14. spectrogram: {
  15. container: '#wave-spectrogram'
  16. },
  17. regions: {
  18. regions: [
  19. {
  20. start: 1,
  21. end: 3,
  22. color: 'hsla(400, 100%, 30%, 0.5)'
  23. },
  24. {
  25. start: 4,
  26. end: 5.4
  27. },
  28. {
  29. start: 6.22,
  30. end: 7.1
  31. }
  32. ]
  33. },
  34. elan: {
  35. url: '../elan/transcripts/001z.xml',
  36. container: '#annotations',
  37. tiers: {
  38. Text: true,
  39. Comments: true
  40. }
  41. }
  42. };
  43. var options = {
  44. container : '#waveform',
  45. waveColor : 'violet',
  46. progressColor : 'purple',
  47. loaderColor : 'purple',
  48. cursorColor : 'navy',
  49. plugins: [
  50. WaveSurfer.minimap.create(pluginOptions.minimap)
  51. ]
  52. };
  53. if (location.search.match('scroll')) {
  54. options.minPxPerSec = 100;
  55. options.scrollParent = true;
  56. }
  57. if (location.search.match('normalize')) {
  58. options.normalize = true;
  59. }
  60. // Init wavesurfer
  61. wavesurfer = WaveSurfer.create(options);
  62. [].forEach.call(document.querySelectorAll('[data-activate-plugin]'), function (el) {
  63. var activePlugins = wavesurfer.initialisedPluginList;
  64. Object.keys(activePlugins).forEach(function(name) {
  65. if (el.dataset.activatePlugin === name) {
  66. el.checked = true;
  67. }
  68. });
  69. });
  70. [].forEach.call(document.querySelectorAll('[data-activate-plugin]'), function (el) {
  71. el.addEventListener('change', function (e) {
  72. var pluginName = e.currentTarget.dataset.activatePlugin;
  73. var activate = e.target.checked;
  74. var options = pluginOptions[pluginName] || {};
  75. var plugin = WaveSurfer[pluginName].create(options);
  76. if (activate) {
  77. wavesurfer.addPlugin(plugin).initPlugin(pluginName);
  78. } else {
  79. wavesurfer.destroyPlugin(pluginName);
  80. }
  81. });
  82. });
  83. /* Progress bar */
  84. (function () {
  85. var progressDiv = document.querySelector('#progress-bar');
  86. var progressBar = progressDiv.querySelector('.progress-bar');
  87. var showProgress = function (percent) {
  88. progressDiv.style.display = 'block';
  89. progressBar.style.width = percent + '%';
  90. };
  91. var hideProgress = function () {
  92. progressDiv.style.display = 'none';
  93. };
  94. wavesurfer.on('loading', showProgress);
  95. wavesurfer.on('ready', hideProgress);
  96. wavesurfer.on('destroy', hideProgress);
  97. wavesurfer.on('error', hideProgress);
  98. }());
  99. wavesurfer.load('../media/demo.wav');
  100. });