转换.wav文件在JavaScript .OGG [英] converting .wav file to .ogg in javascript

查看:465
本文介绍了转换.wav文件在JavaScript .OGG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图捕捉从浏览器用户的音频输入。我与WAV做,但这些文件是真正的大。我的一个朋友告诉我,OGG文件要小得多。
有谁知道如何WAV转换成OGG?
我也有原始数据缓冲区,我并不真的需要转换。但是,我需要的只是OGG EN codeR。

I'm trying to capture user's audio input from the browser. I have done it with WAV but the files are really big. A friend of mine told me that OGG files are much smaller. Does anyone knows how to convert WAV to OGG? I also have the raw data buffer, I don't really need to convert. But I just need the OGG encoder.

这里的WAV途中从马特钻石的RecorderJS codeR :在

Here's the WAV encoder from Matt Diamond's RecorderJS:

function encodeWAV(samples){
  var buffer = new ArrayBuffer(44 + samples.length * 2);
  var view = new DataView(buffer);

  /* RIFF identifier */
  writeString(view, 0, 'RIFF');
  /* file length */
  view.setUint32(4, 32 + samples.length * 2, true);
  /* RIFF type */
  writeString(view, 8, 'WAVE');
  /* format chunk identifier */
  writeString(view, 12, 'fmt ');
  /* format chunk length */
  view.setUint32(16, 16, true);
  /* sample format (raw) */
  view.setUint16(20, 1, true);
  /* channel count */
  view.setUint16(22, 2, true);
  /* sample rate */
  view.setUint32(24, sampleRate, true);
  /* byte rate (sample rate * block align) */
  view.setUint32(28, sampleRate * 4, true);
  /* block align (channel count * bytes per sample) */
  view.setUint16(32, 4, true);
  /* bits per sample */
  view.setUint16(34, 16, true);
  /* data chunk identifier */
  writeString(view, 36, 'data');
  /* data chunk length */
  view.setUint32(40, samples.length * 2, true);

  floatTo16BitPCM(view, 44, samples);

  return view;
}

有一个OGG?

推荐答案

对于那些谁向下投票这个帖子:这真的不是生产向下票问题都没有抽出时间来提供一些洞察为什么问题不知何故坏。我认为这个问题有可取之处,以及海报明明已经花了一些时间试图解决自己的问题。该网络音频规范实际上是意在让正是这种功能,但只是没有接近履行这一宗旨尚未

To those who down-voted this post: It's really not productive to down-vote questions without taking the time to offer some kind of insight into why the question is somehow 'bad'. I think this question has merit, and the poster clearly has spent some time trying to solve the issue on their own. The Web Audio spec is actually intended to allow exactly this kind of functionality, but is just not close to fulfilling that purpose yet:

本规范描述Web应用程序进行处理高层次的JavaScript API和合成声音。主范例是音频路由图,其中多个AudioNode对象被连接在一起,以限定整体音频呈现的。实际的处理将主要发生在底层实现(通常是优化的汇编/ C / C ++ code),而是直接 也支持JavaScript的加工和合成

This specification describes a high-level JavaScript API for processing and synthesizing audio in web applications. The primary paradigm is of an audio routing graph, where a number of AudioNode objects are connected together to define the overall audio rendering. The actual processing will primarily take place in the underlying implementation (typically optimized Assembly / C / C++ code), but direct JavaScript processing and synthesis is also supported.

下面对当前W3C 音频规范草案,这使得以下几点声明:

Here's a statement on the current w3c audio spec draft, which makes the following points:


  • 虽然在JavaScript中处理音频,它是极具挑战性得到可靠的,无干扰的音频同时实现了合理的低延时,特别是在处理器负载较重。

  • JavaScript比高度优化的C ++ code非常慢得多,不能够采取SSE优化和多线程这是获得今天的处理器上获得良好性能的关键优势。优化本地code可以是二十倍的量级更快的JavaScript的处理相比,FFT的。它不适合音频,例如大量的音频源的卷积和三维空间定位的重型加工足够的效率。

  • 的setInterval()和XHR处理将从音频处理偷时间。在一个相当复杂的游戏,就需要对游戏物理和图形一些JavaScript资源。这带来了挑战,因为音频渲染的最后期限驱动(以避免毛刺和获得足够的低延迟)。
    JavaScript不以实时处理线​​程中运行,因而可以是$ P $对抢占由系统上运行的许多其它的线程。

  • 垃圾收集(在Mac OS X自动释放池)可以一个JavaScript线程导致未predictable延迟。

  • 多个JavaScript上下文可以在主线程上运行,窃取时间从上下文做处理。

  • 其它code(比其他的JavaScript),如页面呈现在主线程上运行。

  • 可采取
  • 锁和内存中的JavaScript线程分配。这可能会导致额外的线程preemption。

  • 的问题更是难以用今天的这一代与性能和功耗比较差/电池寿命问题处理器的移动设备。

的ECMAScript(JS)是真的快了很多东西,而且速度越来越快所有这些都取决于发动机间preting的code的时间。然而,对于一些如密集的音频处理,你会使用的编译优化特定的任务资源的低层次的工具好得多。我目前使用在服务器端 的ffmpeg来完成类似的东西。

ECMAScript (js) is really fast for a lot of things, and is getting faster all the time depending on what engine is interpreting the code. For something as intensive as audio processing however, you would be much better off using a low-level tool that's compiled to optimize resources specific to the task. I'm currently using ffmpeg on the server side to accomplish something similar.

我知道这是真的效率低下有发送wav文件横跨互联网连接只是为了获得一个更紧凑的.ogg文件,但是这事用网络音频API的当前状态。做任何客户端处理的用户必须明确给出访问本地文件系统和执行权限的文件进行转换。希望有人会很快解决这个突出的问题。祝你好运。

I know that it is really inefficient to have to send a wav file across an internet connection just to obtain a more compact .ogg file, but that's the current state of things with the web audio api. To do any client-side processing the user would have to explicitly give access to the local file system and execution privileges for the file to make the conversion. Hopefully someone will address this glaring problem soon. Good luck.

编辑:您也可以使用谷歌的本地客户端,如果​​你不介意限制用户Chrome浏览器。这似乎是加载在沙盒中,实现速度几乎一样好本地执行code非常有前途的技术。我假设会有其他浏览器类似的实现在某些时候。

You could also use Google's native-client if you don't mind limiting your users to Chrome. It seems like very promising technology that loads in a sandbox and achieves speeds nearly as good natively executed code. I'm assuming that there will be similar implementations in other browsers at some point.

这篇关于转换.wav文件在JavaScript .OGG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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