标签:src rip base64 sel har base read das split
音频文件转base64
<input type="file" id="fileInput"> <script> var fileInput = document.querySelector(‘#fileInput‘); fileInput.onchange = function () { var file = this.files[0]; var reader = new FileReader(); reader.readAsDataURL(file); reader.onload = function () { var data = reader.result; console.log(‘data‘, data); }; }; </script>
base64转音频文件
<script> const dataurl="****"; const url = URL.createObjectURL(dataURLtoBlob(dataurl)); //接着把url赋值给audio的src。 function dataURLtoBlob(dataurl) { var arr = dataurl.split(‘,‘), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } return new Blob([u8arr], { type: mime }); }; </script>
标签:src rip base64 sel har base read das split
原文地址:https://www.cnblogs.com/EllenChen/p/13140688.html