Encode audio from getUserMedia() to a .OGG in JavaScript [duplicate]

心不动则不痛 提交于 2019-12-03 10:03:18

问题


So I have this HTML5 project I'm working on, where I'm converting an iOS app to a web-based one. Accompanying part of the content creation of the app is an audio recording, which I'm trying to replicate in JavaScript without the use of plugins; so far, I've been able to record audio from getUserMedia(), and turn it into a WAV thanks to Recorder.js.

Now, however, I'm a bit lost. I currently have two separate views, one for recording content and one for playing it back, but I don't know how to get the audio exported form Recorder.js into my JSON payload for playback (I'd like to avoid forcing a server upload or client download).

So I guess my specific question is, how do I take the blob object (something I know almost nothing about) made by Recorder.js and turn it into either raw data, or somehow send the File through JSON?

UPDATE: I've decided to try and use the speex.js tool (https://github.com/jpemartins/speex.js) to encode a .OGG (much smaller than a .WAV). However, I'm not really sure how to use it; the demo page didn't seem to work for me, and trying to call the .encode() function of a Speex object doesn't seem to actually encode the data, I only get zeros in the object fields. Does anyone know of any resources where I can learn how to use this type of tool?


回答1:


There is a library (MIT licenced) which should work, I believe I have seen this exact library being used for saving ogg files from a getUserMedia audio stream on a website not long ago. I vaguely remembered the library name, but I think this is the one:

https://github.com/streamproc/MediaStreamRecorder/blob/master/AudioStreamRecorder/MediaRecorder.js

The whole project on GitHub: https://github.com/streamproc/MediaStreamRecorder/

Since it seems so hard to achieve this, it might at least be worth a look to understand the concepts - but I'd say it's rather advanced javascript we are dealing with here...



来源:https://stackoverflow.com/questions/16821919/encode-audio-from-getusermedia-to-a-ogg-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!