问题描述
看来,它支持spx: http://dev.w3.org/html5/spec-preview /the-source-element.html
from html5 spec, it seem support spx:http://dev.w3.org/html5/spec-preview/the-source-element.html
使用:
但是从我的尝试来看,它不能同时在Firefox 17和Chrome中播放,您能帮上忙吗?
But from my trying, it can't play in both Firefox 17 and Chrome, could you help ?
推荐答案
我在GitHub上发现了speex.js( https://github.com/jpemartins/speex.js )可以解决您的问题.使用speex.js,您可以将&迅速将speex文件(* .spx或* .ogg)解码为wav,Chrome/Firefox和许多其他支持HTML5的现代浏览器都支持.
I have found that speex.js on GitHub (https://github.com/jpemartins/speex.js) can solve your problem. With speex.js you can demux & decode speex file (*.spx or *.ogg) to wav on fly, which is supported by both Chrome/Firefox and many other modern browsers HTML5 ready.
<script src="bitstring.js"></script>
<script src="pcmdata.min.js"></script>
<script src="speex.js"></script>
- 下面的函数将完成将spx转换为wav编解码器的技巧:
/**
* @param bufSpx ArrayBuffer (Uint8Array) holding content of speex file (*.spx or *.ogg)
*/
function decodeFile(bufSpx) {
var stream, samples, st;
var ogg, header, err;
ogg = new Ogg(bufSpx, {file: true});
ogg.demux();
stream = ogg.bitstream();
header = Speex.parseHeader(ogg.frames[0]);
console.log(header);
comment = new SpeexComment(ogg.frames[1]);
console.log(comment.data);
st = new Speex({
quality: 8,
mode: header.mode,
rate: header.rate
});
samples = st.decode(stream, ogg.segments);
var waveData = PCMData.encode({
sampleRate: header.rate,
channelCount: header.nb_channels,
bytesPerSample: 2,
data: samples
});
// array buffer holding audio data in wav codec
var bufWav = Speex.util.str2ab(waveData);
// convert to a blob object
var blob = new Blob([bufWav], {type: "audio/wav"});
// return a "blob://" url which can be used as a href anywhere
return URL.createObjectURL(blob);
}
这篇关于如何通过html5播放.spx文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!