Javascript制作音频blob [英] Javascript make audio blob

查看:461
本文介绍了Javascript制作音频blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试html音频标签,我想制作音频blob网址,就像youtube或vimeo一样,然后将其添加到src开始播放音频。

I am testing the html audio tag and I would like to make audio blob url's, like youtube or vimeo does, and add it to the "src" to start playing the audio.

我一直在测试新的Blob()网址.createObjectURL()但我不知道如何使用它。

I've been testing with new Blob() and URL.createObjectURL() but I don't know how to use it.

我想做的事情如下:
< audio controls srcblob:null / 8142a612-29ad-4220-af08-9a31c55ed078>< / audio>

非常感谢你的帮助。

推荐答案

假设你有这样的base64编码音频版本

Suppose you have base64 encoded version of audio like this

data="data:audio/ogg;base64,T2dnUwACAAAAAAAAAADSeWyXAU9nZ1MAAAAAAAAAAAAA0nl";

1.首先删除base64头文件(前导码)并将其解码为纯二进制格式,形式为就像你的iPad一样。您可以使用 convertDataURIToBinary 作为 borismus

1.First remove the base64 headers (preamble) and decode it to pure binary form, the form it lies in as in your iPad. You can use convertDataURIToBinary an excellent snippet by borismus on github for that

var binary= convertDataURIToBinary(data);

2.现在从二进制文件中创建一个Blob;指定音频类型

2.Now create a Blob from the binary; specifying the type of audio it is

var blob=new Blob([binary], {type : 'audio/ogg'});

3.现在从这个Blob中创建blob url

3.Now create blob url out of this Blob

var blobUrl = URL.createObjectURL(blob);

现在只需更换 src 属性< source> 到此blob url。如果您已经拥有纯解码二进制文件,那么您只需执行第3步

That's all now simply replace src attribute of <source> to this blob url.In case you already have the pure decoded binary then you just do step 3

https://jsfiddle.net/sanddune/uubnnr0w/

这篇关于Javascript制作音频blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆