11

I have wasted a ton of time implementing multiple audio recording options in a website I'm building but each one either only works in Chrome, only in Firefox, both but not Safari, and none work on iOS.

The website needs to allows the user to record their message and save it in a form state for submission.

All the current articles I am reading are a few months old and mention that iOS doesn't/will support it soon. I've tried mobile Chrome on iOS and it still didn't work.

Has anyone found a way to simply record audio in a browser as well as mobile website??

Things I've tried:

Currently using the following code which works, for Chrome and 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"/>

Using the Francium Voice library:

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();
});  
Travis Johnston
  • 453
  • 2
  • 5
  • 17
  • `have wasted a ton of time implementing multiple audio recording options` please show us what you've implemented – messerbill Feb 08 '18 at 15:17
  • I added the different methods. – Travis Johnston Feb 08 '18 at 15:25
  • please post your `code` – messerbill Feb 08 '18 at 15:30
  • 4
    Sorry, i'm not posting hundreds of lines of code from various implementations for this and I don't think it's required in order to get an accurate or suggested answer to my OP. – Travis Johnston Feb 08 '18 at 15:35
  • of course i am talking about the `relevant code`. But if you don't wanna do this it is ok - in this case i guess you need to wait ages for an answer....if one will come one day – messerbill Feb 08 '18 at 15:37
  • Added 1 of the ones I'm using. – Travis Johnston Feb 08 '18 at 15:41
  • Possible duplicate of [How to record audio on webpage (iOS, Android, PC/Mac) - no flash](https://stackoverflow.com/questions/19815442/how-to-record-audio-on-webpage-ios-android-pc-mac-no-flash) – octavn Jul 10 '18 at 19:14
  • See [my answer](https://stackoverflow.com/a/51272250/813988) to [How to record audio on webpage (iOS, Android, PC/Mac)](https://stackoverflow.com/questions/19815442/how-to-record-audio-on-webpage-ios-android-pc-mac-no-flash/). – octavn Jul 10 '18 at 19:16

1 Answers1

6

I found a technique that finally worked on Chrome, Firefox, and iOS Safari. There is an issue with getUserMedia in Safari though but I'm looking into that now.

https://github.com/GersonRosales/Record-Audios-and-Videos-with-getUserMedia

Travis Johnston
  • 453
  • 2
  • 5
  • 17