templates/base64-to-audio.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}
  3. ToBase64.dev - Decode base64 audio and get decoded audio
  4. {% endblock %}
  5. {% block h1 %}Decode base64 to audio{% endblock %}
  6. {% block body %}
  7. <div class="row" style="height: 60%;">
  8. <div class="padding col-5">
  9. <form method="post" action="" class="form" style="height: 100%">
  10. <textarea class="form-control" id="input4" name="input3" placeholder="Type (or paste) here..." spellcheck="false" style="width: 100%;height: 100%;"></textarea>
  11. </form>
  12. </div>
  13. <div class="col-2 d-flex flex-column">
  14. <div class="padding row" style="margin-top:auto;margin-bottom:auto;">
  15. <button type="button" onclick="toaudio()" class="col-12 btn btn-info"><i class="fas fa-long-arrow-alt-right"></i></button>
  16. </div>
  17. </div>
  18. <div class="padding col-5 d-flex flex-column">
  19. <div style="height: 85%">
  20. <audio controls class="form-control" id="audio" name="output" placeholder="Output will be displayed here..." spellcheck="false" style="width: 100%;height: 100%;">
  21. <source id="output4" src="data:image/png;base64," type="audio/mpeg">
  22. Your browser does not support the audio element.
  23. </audio>
  24. </div>
  25. <button id="download" type="button" class="btn btn-info" onclick="download()" style="margin-top:auto;">Download file!</button>
  26. </div>
  27. </div>
  28. <script type="text/javascript">
  29. // Add the following code if you want the name of the file appear on select
  30. $(".custom-file-input").on("change", function() {
  31. var fileName = $(this).val().split("\\").pop();
  32. $(this).siblings(".custom-file-label").addClass("selected").html(fileName);
  33. });
  34. function copyToClipboard(element) {
  35. var copyText = document.getElementById(element);
  36. copyText.select();
  37. document.execCommand("copy");
  38. }
  39. function download() {
  40. var url = document.getElementById('output4').src.replace(/^data:audio\/[^;]+/, 'data:audio/mpeg');
  41. var link = document.createElement('a');
  42. link.href = url;
  43. link.download = 'audio.mp3';
  44. document.body.appendChild(link);
  45. link.click();
  46. document.body.removeChild(link);
  47. //window.open(url);
  48. }
  49. function toimage() {
  50. var string = document.getElementById('input3').value;
  51. var image = "data:image/png;base64," + string;
  52. document.getElementById('output3').src = image;
  53. document.getElementById('download').disabled = false;
  54. }
  55. function toaudio() {
  56. var string = document.getElementById('input4').value;
  57. var audio = "data:audio/mpeg;base64," + string;
  58. document.getElementById('output4').src = audio;
  59. document.getElementById('download').disabled = false;
  60. document.getElementById('audio').load();
  61. }
  62. function totext() {
  63. var Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function(e) { var t = ""; var n, r, i, s, o, u, a; var f = 0;
  64. e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++);
  65. r = e.charCodeAt(f++);
  66. i = e.charCodeAt(f++);
  67. s = n >> 2;
  68. o = (n & 3) << 4 | r >> 4;
  69. u = (r & 15) << 2 | i >> 6;
  70. a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function(e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0;
  71. e = e.replace(/\\+\\+[++^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++));
  72. o = this._keyStr.indexOf(e.charAt(f++));
  73. u = this._keyStr.indexOf(e.charAt(f++));
  74. a = this._keyStr.indexOf(e.charAt(f++));
  75. n = s << 2 | o >> 4;
  76. r = (o & 15) << 4 | u >> 2;
  77. i = (u & 3) << 6 | a;
  78. t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function(e) { e = e.replace(/\r\n/g, "\n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192);
  79. t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224);
  80. t += String.fromCharCode(r >> 6 & 63 | 128);
  81. t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function(e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r);
  82. n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1);
  83. t += String.fromCharCode((r & 31) << 6 | c2 & 63);
  84. n += 2 } else { c2 = e.charCodeAt(n + 1);
  85. c3 = e.charCodeAt(n + 2);
  86. t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
  87. n += 3 } } return t } }
  88. // Define the string
  89. var string = document.getElementById('input4').value;
  90. // Encode the String
  91. var decodedString = Base64.decode(string);
  92. document.getElementById('output4').value = decodedString;
  93. }
  94. function tobase64() {
  95. var Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function(e) { var t = ""; var n, r, i, s, o, u, a; var f = 0;
  96. e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++);
  97. r = e.charCodeAt(f++);
  98. i = e.charCodeAt(f++);
  99. s = n >> 2;
  100. o = (n & 3) << 4 | r >> 4;
  101. u = (r & 15) << 2 | i >> 6;
  102. a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function(e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0;
  103. e = e.replace(/\\+\\+[++^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++));
  104. o = this._keyStr.indexOf(e.charAt(f++));
  105. u = this._keyStr.indexOf(e.charAt(f++));
  106. a = this._keyStr.indexOf(e.charAt(f++));
  107. n = s << 2 | o >> 4;
  108. r = (o & 15) << 4 | u >> 2;
  109. i = (u & 3) << 6 | a;
  110. t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function(e) { e = e.replace(/\r\n/g, "\n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192);
  111. t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224);
  112. t += String.fromCharCode(r >> 6 & 63 | 128);
  113. t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function(e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r);
  114. n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1);
  115. t += String.fromCharCode((r & 31) << 6 | c2 & 63);
  116. n += 2 } else { c2 = e.charCodeAt(n + 1);
  117. c3 = e.charCodeAt(n + 2);
  118. t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
  119. n += 3 } } return t } }
  120. // Define the string
  121. var string = document.getElementById('input2').value;
  122. // Encode the String
  123. var encodedString = Base64.encode(string);
  124. document.getElementById('output2').value = encodedString;
  125. }
  126. </script>
  127. <style>
  128. </style>
  129. <script>
  130. function handleFileSelect(evt) {
  131. document.getElementById("loading").style.display = "";
  132. var files = evt.target.files; // FileList object
  133. // Loop through the FileList and render image files as thumbnails.
  134. for (var i = 0, f; f = files[i]; i++) {
  135. // Only process image files.
  136. if (!f.type.match('image.*')) {
  137. continue;
  138. }
  139. var reader = new FileReader();
  140. // Closure to capture the file information.
  141. reader.onload = (function(theFile) {
  142. return function(e) {
  143. // Render thumbnail.
  144. document.getElementById('imageb64').src = e.target.result;
  145. document.getElementById("output3").value = "url('" + e.target.result + "')";
  146. document.getElementById("output2").value = e.target.result;
  147. document.getElementById("output1").value = e.target.result.split(',')[1];
  148. imageB64 = e.target.result;
  149. document.getElementById("loading").style.display = "none";
  150. };
  151. })(f);
  152. // Read in the image file as a data URL.
  153. reader.readAsDataURL(f);
  154. }
  155. }
  156. //document.getElementById('files').addEventListener('change', handleFileSelect, false);
  157. </script>
  158. {% endblock %}