Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS + HTML5 record audio file

I'm looking for a simple solution to record audio file and upload it to s3.

My web searches come up to find:

WebRTC-Experiment which is the most popuplar solution i could find.

it also have a working example in the following link : https://www.webrtc-experiment.com/RecordRTC/

I also found ngCamRecorder which wasn't supported by firefox yet.

I'm looking for a simple solution + working example, and suggestion.

  1. Which solution is most popuplar to use with AngularJS?

  2. if you can provide your own example or link to a working example that i can use.

  3. if you also used S3 i would like to know how you can push the file to S3, and get the link to the controller.

The solution i found, throw error, and include a working example without the code itself explained. I also would like to know how to push it to s3.

This is the code i implemented from the example:

$scope.start_recording = function()
{
    navigator.getUserMedia(session, function (mediaStream) {
        window.recordRTC = RecordRTC(MediaStream);
        recordRTC.startRecording();
    }, function(error){console.log(error)});
};

$scope.stop_recording = function()
{
    navigator.getUserMedia({audio: true}, function(mediaStream) {
        window.recordRTC = RecordRTC(MediaStream);
        recordRTC.startRecording();
    });
};

It simply throw an error: undefined is not a function on recordrtc.js line 641

  if(!mediaStream.getAudioTracks().length) throw 'Your stream has no audio tracks.';

obviously mediaStrem is null.

Thanks.

like image 252
Liad Livnat Avatar asked Sep 09 '14 13:09

Liad Livnat


People also ask

How do I record audio with JavaScript?

In order to start the audio recording, an audio stream must be created. This is done by calling the getUserMedia() method on the navigator. mediaDevices interface. The getUserMedia() will return a promise and when that promise resolves, the audio stream will be successfully created and available in the .

What is RecordRTC?

RecordRTC is WebRTC JavaScript library for audio/video as well as screen activity recording. It supports Chrome, Firefox, Opera, Android, and Microsoft Edge. Platforms: Linux, Mac and Windows.

How do I record audio in react?

Recording AudioSet up two buttons and an HTML5 audio tag in the render() function. To start the audio recording call the start() function in the Mp3Recorder which in turn returns a Promise. }; Now the audio starts to record once the above function is called.


1 Answers

There's an AngularJS wrapper for this, it's a simple directive that supports HTML5 (RecorderJS), Cordova Media and Flash.

Usage is straightforward

<ng-audio-recorder audio-model="someModel" auto-start="false">
   <!-- controls -->
   <button ng-click='recorder.startRecording()'>Start</button>
   <button ng-click='recorder.stopRecording()'>Stop</button>
</ng-audio-recorder>

You can see the full usage here:

https://github.com/logbon72/angular-recorder

like image 103
tlogbon Avatar answered Sep 27 '22 21:09

tlogbon