Skip to content

Instantly share code, notes, and snippets.

@niusounds
Created August 27, 2014 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save niusounds/b359389e8f6493d29f50 to your computer and use it in GitHub Desktop.
Save niusounds/b359389e8f6493d29f50 to your computer and use it in GitHub Desktop.
WebAudio + WebRTC (getUserMedia) + AngularJS sample
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>HelloAudio</title>
</head>
<body ng-controller="Main">
<input type="range" min="20" max="4000" ng-model="hz.value" step="0.01">
<input type="range" min="0" max="1" ng-model="gain.value" step="0.01">
<script src="angular.min.js"></script>
<script src="window.js"></script>
</body>
</html>
angular.module('myApp', []).factory('audioContext', function() {
return new AudioContext();
}).factory('getUserMedia', function($window) {
return function(opts) {
return new Promise(function(resolve, reject) {
$window.navigator.webkitGetUserMedia(opts, resolve, reject);
});
};
}).controller('Main', function($scope, audioContext, getUserMedia) {
getUserMedia({
audio: true
}).then(function(stream) {
// mic in
var source = audioContext.createMediaStreamSource(stream);
var filter = audioContext.createBiquadFilter();
filter.frequency.value = 200;
filter.type = 'highpass';
var gain = audioContext.createGain();
gain.gain.value = 0;
source.connect(filter);
filter.connect(gain);
gain.connect(audioContext.destination);
$scope.hz = filter.frequency;
$scope.gain = gain.gain;
$scope.$apply();
}, function(err) {
console.log(err)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment