从azure blob存储内存流中获取wave文件

问题描述:

我想从一个blob存储容器中下载一个wav文件。我有URL在我的角度应用程序上进行流式处理,但是我需要重新取样。从blob存储中获取字节数组看起来像这样:从azure blob存储内存流中获取wave文件

“字节”:“UklGRqS3AQBXQVZFZm10IBAAAAABAAEAoA8AAEAfAAACABAAZGF0YYC3AQDg92H4xPzwAHf + RP9HAB4ATwFjAZgBoAEtASMBMQGGAR ........”

我试图创建一个BLOB文件,但我得到一个空的.wav文件

var blob = new Blob([bytes],{type:“audio/x-wav”});

saveAs(blob,“file.wav”);

如何获取.wav文件格式(https://en.wikipedia.org/wiki/WAV#RIFF)以便我可以重新采样并下载它?

看起来好像您正在使用FileSaver.js。以下是我的完整示例代码,它从Azure blob存储中以Angularjs 1.xFileSaver.js下载图像文件。它运作良好,你可以把它作为参考。

的index.html

<!doctype html> 
<html ng-app="project"> 

<head> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
    <script src="https://cdn.rawgit.com/eligrey/Blob.js/0cef2746414269b16834878a8abc52eb9d53e6bd/Blob.js"></script> 
    <script src="https://cdn.rawgit.com/eligrey/FileSaver.js/e9d941381475b5df8b7d7691013401e171014e89/FileSaver.min.js"></script> 
    <script> 
     angular.module('project', []) 

     .controller('ProjectController', function($http) { 
      var project = this; 
      project.yourName = "There"; 

      project.download = function() { 
       var blobURL = "https://<my-storage-accout>.blob.core.windows.net/myimages/image.jpg"; 
       $http.get("blobURL", { 
        responseType: "arraybuffer" 
       }). 
       then(function(res) { 
        console.log("Read blob with " + res.data.byteLength + " bytes in a variable of type '" + typeof(res.data) + "'"); 

        var blob = new Blob([res.data], { 
         type: "image/jpeg" 
        }); 
        var filename = 'image.jpg'; 
        saveAs(blob, filename); 

       }, function(data, status) { 
        console.log("Request failed with status: " + status); 
       }); 
      } 
     }) 
    </script> 
</head> 

<body> 
    <div ng-controller="ProjectController as pro"> 

     <h1>Hello {{pro.yourName}}!</h1> 
     <button type="button" ng-click="pro.download()">download</button> 
    </div> 
</body> 

</html>