本文介绍了Chrome上的JavaScript中的音频记录,始终将视频/ogg发送到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直试图在Chrome上以OGG格式录制音频,然后将其发送回服务器,但是它始终以视频/ogg格式获取音频.这是我所拥有的:
I have been trying to record audio in OGG format on Chrome and send it back to the server, but it always gets their in video/ogg format. Here is what I have:
捕获音频:
let chunks = [];
let recording = null;
let mediaRecorder = new MediaRecorder(stream);
mediaRecorder.start();
mediaRecorder.onstop = function() {
recording = new Blob(chunks, { 'type' : 'audio/ogg; codecs=opus' });
}
mediaRecorder.ondataavailable = function(e){
chunks.push(e.data);
}
将其发送到服务器:
let data = new FormData();
data.append('audio', recording);
jQuery.ajax(...);
blob到达后端,但始终在video/ogg中!
The blob gets to the backend, but always in video/ogg!
推荐答案
我最终使用了 kbumsik/opus-media-recorder ,为我解决了此问题.MediaRecorder的直接替代品.
I ended up using kbumsik/opus-media-recorder, solved the issue for me. A drop-in replacement for MediaRecorder.
这篇关于Chrome上的JavaScript中的音频记录,始终将视频/ogg发送到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!