简体   繁体   English

使用Javascript SDK将WebAudio数据发布到Soundcloud轨道

[英]Post WebAudio data to Soundcloud track using Javascript SDK

I'm trying to use an audio buffer composed of Float32Array s (1 for each channel) as asset data to create a soundcloud track. 我正在尝试使用由Float32Array组成的音频缓冲区(每个通道1个)作为资产数据来创建音云音轨。 The audio buffer for a mono recording looks like this: 单声道录音的音频缓冲区如下所示:

[Float32Array { 0=-0.0001220703125,  1=0.000579833984375,  2=0.000762939453125,  ...}]

So I assume that I should convert it to a binary string. 因此,我假设我应该将其转换为二进制字符串。 To know the correct encoding, I took a look at http://connect.soundcloud.com/examples/recording.html It's flash but at the end the following post is done: 为了知道正确的编码,我看了一看http://connect.soundcloud.com/examples/recording.html它是Flash,但最后完成了以下文章:

audio.wav
--ievejmnijdgyooinchslwnpygpivapif
Content-Disposition: form-data; name="track[asset_data]"; filename="audio.wav"
Content-Type: application/octet-stream

RIFF(WAVEfmt D¬XdataÚÿÇÿÿ+ÿc]ÿ1&»ÿUÿ(1ÊÿEc&môã...

In order to turn my audio buffer into such, I used code similar to https://gist.github.com/kevincennis/9754325 so that now my process looks like: 为了将音频缓冲区变成这样,我使用了类似于https://gist.github.com/kevincennis/9754325的代码,所以现在我的过程看起来像:

worker.onmessage = function( e ) {
  var blob = e.data;
  var reader = new window.FileReader();
  reader.onloadend = function() {
     var binaryData = reader.result;                
     SC.post('/tracks', {
       asset_data : binaryData,
       title : 'recording'
     });
  };
  reader.readAsText(blob);
});

Still, there should be some problem with the encoding. 尽管如此,编码还是应该有一些问题。 The above, produces the following post: 上面产生了以下帖子:

_status_code_map[302]   200
asset_data              RIFF ���WAVEfmt �����D�������data����
format                  json
oauth_token             1....
title                   recording

but the response of Soundclound API is still: "NetworkError: 422 Unprocessable Entity - https://api.soundcloud.com/tracks " 但Soundclound API的回应仍是:“NetworkError:422无法处理的实体- https://api.soundcloud.com/tracks

Can anybody spot what's wrong? 任何人都可以发现问题所在吗?

Turns out that Soundcloud only accept the request if it's in multipart form encoding. 事实证明,Soundcloud仅接受采用多部分形式编码的请求。 It seems not possible to me to achieve this using the SDK. 我似乎无法使用SDK来实现这一目标。 This is the code using angular.js: 这是使用angular.js的代码:

worker.onmessage = function( e ) {
  var blob = e.data;
  var fd = new FormData();
  fd.append('oauth_token', SC.accessToken());
  fd.append('format','json');
  fd.append('track[title]', 'recording');
  fd.append('track[asset_data]', blob);

  $http.post('https://api.soundcloud.com/tracks', fd, {
    transformRequest: angular.identity,
    headers: {'Content-Type': undefined}
  })
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM