【发布时间】:2018-07-19 05:16:30
【问题描述】:
我已经浪费了大量时间在我正在构建的网站中实现多个音频录制选项,但每个选项都只能在 Chrome 中工作,只能在 Firefox 中工作,两者都不能在 Safari 上工作,而且在 iOS 上都不能工作。
网站需要允许用户记录他们的消息并将其保存为表单状态以供提交。
我正在阅读的所有当前文章都是几个月前的,并提到 iOS 不/将很快支持它。我已经在 iOS 上尝试了移动 Chrome,但它仍然无法正常工作。
有没有人找到一种方法来简单地在浏览器和移动网站中录制音频??
我尝试过的事情:
- Francium Voice(一个废弃的 javascript 项目,适用于 Chrome。记录和保存,我可以通过表单数据发送音频文件。https://subinsb.com/html5-record-mic-voice/。但这使用显示为“错误”的
- 我开始尝试 getUserMedia(),因为这似乎是新标准,并表示它支持更多设备/浏览器,但麦克风也无法在 iOS 上使用。 https://www.html5rocks.com/en/tutorials/getusermedia/intro/
- 很多文章说要使用Record.js,https://github.com/mattdiamond/Recorderjs,但这也是一个废弃的项目。我只能让音频录制,但它没有保存它。再次无法在 Safari 或 iOS 中运行。
- 我尝试使用音频/* 技术,但无法正常工作。它只会显示一个上传按钮,无法显示麦克风选项。根据文档,它似乎是“应该”工作的那个。 https://developers.google.com/web/fundamentals/media/recording-audio/
目前使用以下适用于 Chrome 和 Firefox 的代码。
HTML
<audio controls src="" id="audio"></audio>
<a class="button" id="record">Record</a>
<input type="hidden" id="audiofile" name="audiofile" value="" aria-hidden="true"/>
使用 Francium Voice 库:
Javascript
// Audio Recording for Phone Calls
$(document).on("click", "#record:not(.stop)", function(){
elem = $(this);
$("#audio").attr("src","");
$("#audiofile").val("");
Fr.voice.record($("#live").is(":checked"), function(){
elem.addClass("stop");
});
elem.html("Stop <label id='minutes'>00</label>:<label id='seconds'>00</label>");
var minutesLabel = document.getElementById("minutes");
var secondsLabel = document.getElementById("seconds");
var totalSeconds = 0;
setInterval(setTime, 1000);
function setTime() {
++totalSeconds;
secondsLabel.innerHTML = pad(totalSeconds % 60);
minutesLabel.innerHTML = pad(parseInt(totalSeconds / 60));
}
function pad(val) {
var valString = val + "";
if (valString.length < 2) {
return "0" + valString;
} else {
return valString;
}
}
});
$(document).on("click", ".stop", function(){
elem = $(this);
elem.html("Record");
elem.removeClass("stop");
Fr.voice.export(function(base64){
$("#audio").attr("src", base64);
$("#audiofile").val(base64);
$("#audio")[0].play();
}, "base64");
Fr.voice.stop();
});
【问题讨论】:
-
have wasted a ton of time implementing multiple audio recording options请告诉我们你实现了什么 -
我添加了不同的方法。
-
请发布您的
code -
对不起,我没有为此发布来自各种实现的数百行代码,我认为不需要它来获得对我的 OP 的准确或建议的答案。
-
当然我说的是
relevant code。但是,如果您不想这样做,那没关系-在这种情况下,我想您需要等待很长时间才能得到答案....如果有一天会来
标签: javascript ios html html5-audio audio-recording