Audio stream to web audio api

1,938 views
Skip to first unread message

Ramasundar Kandasamy

unread,
Nov 22, 2012, 2:00:15 PM11/22/12
to discuss...@googlegroups.com
Hi,

I am trying to capture the audio and pass the stream to the web audio api. No success.

I tired all the possible microphones that is available on my system (webcam mic, built in mic, headphone mic).

Did any one have success on windows environment?

I am running (stable) Chrome Version 23.0.1271.64 m.

Thanks,
Ram
   
 function start() {
    navigator
.webkitGetUserMedia({ audio : true }, gotStream);
   
}
   
   
// success callback when requesting audio input stream
   
function gotStream(stream) {
   
   
var audioContext = new webkitAudioContext();
   
   
// Create an AudioNode from the stream.
   
var mediaStreamSourceNode = audioContext.createMediaStreamSource(stream);
   
   
// Connect it to the destination to hear yourself (or any other node for processing!)
    mediaStreamSourceNode
.connect(audioContext.destination);
   
    log
("inside gotstream...");
   
}
   
   
function log(pText) {
    console
.log(pText);
   
}



PhistucK

unread,
Nov 22, 2012, 3:28:31 PM11/22/12
to discuss...@googlegroups.com
It is disabled by default, if it even exists in Chrome 23.
Go to about:flags and enable "Web Audio Input".

PhistucK



--
 
 
 

Ramasundar Kandasamy

unread,
Nov 23, 2012, 2:17:41 AM11/23/12
to discuss...@googlegroups.com
Yes. Of course. I switched it on.


in the above link int is mentioned that the input and output device should be using same sample rate. How can one figure out that?

Thanks
Ram

Henrik Andreasson

unread,
Nov 23, 2012, 3:53:10 AM11/23/12
to discuss...@googlegroups.com
Open the Multimedia property dialog, e.g. by calling mmsys.cpl from command line.

- Select Playback and Properties for your default device. Check the sample rate in the Advanced tab.
- Select Recording and Properties for your default device. Check the sample rate in the Advanced tab.
- Ensure that the same device is used in both directions and that both use the same sample rate and channel setup.




--
 
 
 

navjyot pankaj

unread,
Jul 26, 2013, 4:21:12 AM7/26/13
to discuss...@googlegroups.com
Check it out this code its working for me///Audio merge and paly


<audio id="playaudio" controls></audio>
       <audio id="back">
       </audio>
      <script src="~/Scripts/jquery-1.7.1.js"></script>
<script src="~/Scripts/jquery-ui-1.8.17.custom.min.js"></script>
    <input onclick="startRecording()" type="button" value="start recording" />
    <input onclick="stopRecording()" type="button" value="stop recording and play" />

     

     

    <script>
        var onFail = function (e) {
            console.log('Rejected!', e);
        };

        var onSuccess = function (s) {
            stream = s;
        }

        window.URL = window.URL || window.webkitURL;
        navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;

        var stream;
        var audio = document.getElementById("playaudio");

        function startRecording() {
            if (navigator.getUserMedia) {
                navigator.getUserMedia({ audio: true }, onSuccess, onFail);
               
            } else {
                console.log('navigator.getUserMedia not present');
            }
        }

        function stopRecording() {
            var streamRecorder;
            var context = new webkitAudioContext();
            var analyser = context.createAnalyser();
            var microphone = context.createMediaStreamSource(stream);
            var bgAudio = document.getElementById("back");
            var backgroundMusic = context.createMediaElementSource(bgAudio);
            bgAudio.volume = 0.03;
            $("#back").get(0).play();
            var analyser = context.createAnalyser();
            var mixedOutput = context.createMediaStreamDestination();
            microphone.connect(analyser);
            analyser.connect(mixedOutput);
            backgroundMusic.connect(mixedOutput);
            
           // requestAnimationFrame(drawAnimation);

           // streamRecorder = mixedOutput.stream.record();
          
            audio.src = window.URL.createObjectURL(mixedOutput.stream);
            alert(audio.src);
        }
    </script>
Reply all
Reply to author
Forward
0 new messages