admin管理员组文章数量:1435859
I have a WAV file in Blob and in order to convert it to MP3 I need to convert it to Int16Array first (to follow the example from here: ).
E.g.
var mp3encoder = new lamejs.Mp3Encoder(2, 44100, 128);
// instead of `var samples = new Int16Array(44100);` I want something like `var samples = new Int16Array(blob);`
var mp3Tmp = mp3encoder.encodeBuffer(samples);
Is this possible?
I have a WAV file in Blob and in order to convert it to MP3 I need to convert it to Int16Array first (to follow the example from here: https://github./zhuker/lamejs).
E.g.
var mp3encoder = new lamejs.Mp3Encoder(2, 44100, 128);
// instead of `var samples = new Int16Array(44100);` I want something like `var samples = new Int16Array(blob);`
var mp3Tmp = mp3encoder.encodeBuffer(samples);
Is this possible?
Share Improve this question asked May 23, 2016 at 15:08 Alex NetkachovAlex Netkachov 13.6k7 gold badges55 silver badges90 bronze badges 2- You have to employ the FileReader API: stackoverflow./questions/15341912/… – lipp Commented May 23, 2016 at 15:17
- Did you manage to sort this out? – Mac_W Commented Jun 24, 2019 at 14:39
1 Answer
Reset to default 3Provided you know the data is actually a blob of 16-bit int
s, then yes, it's possible:
Read the
Blob
into anArrayBuffer
via itsarrayBuffer
method (the original answer had to useFileReader
, but nowBlob
has anarrayBuffer
method; see the edit history if for some reason you have to support old environments without it):samples.arrayBuffer() .then(buffer => { // ... }) .catch(error => { // ...handle/report error... });
View the
ArrayBuffer
as anInt16Array
via theInt16Array
constructor:const data = new Int16Array(buffer);
Now data
is the array buffer from the blob viewed as an Int16Array
.
Something along these lines:
samples.arrayBuffer()
.then(buffer => {
const data = new Int16Array(buffer);
// ...use `data` here...
})
.catch(error => {
// ...handle/report error...
});
本文标签: javascriptHow to convert Blob to Int16ArrayStack Overflow
版权声明:本文标题:javascript - How to convert Blob to Int16Array - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745674439a2669767.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论