O
O
Olya Pilipenko2014-04-09 12:29:31
JavaScript
Olya Pilipenko, 2014-04-09 12:29:31

Microphone in Web Audio API

Good afternoon! There is an html page and a js script connected to it that implements the microphone:

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="tn.js"></script>
</head>
<body>
<script>
window.onload = navigator.getUserMedia({audio: true}, gotStream);
</script>
</body>
</html>

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;

function gotStream (stream) {
  window.AudioContext = window.AudioContext || window.webkitAudioContext;
  var audioContext = new AudioContext();

  var mediaStreamSource = audioContext.createMediaStreamSource(stream);

  mediaStreamSource.connect(audioContext.destination);
}

Why is the microphone not working on page load?
If you just enter the script into the console and call it navigator.getUserMedia({audio: true}, gotStream), then everything works?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Perkovec, 2014-04-09
@pilipolya

Here they deal with the microphone sohabr.ru/post/211905

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question