语言

Menu
Sites
Language
How to analyze an audio stream from the mic

Hi, everybody!

I'm trying to get the frequency information from audio stream from the microphone. I tried the following:

 

if (navigator.webkitGetUserMedia) {
   navigator.webkitGetUserMedia({ audio: true },
      function(stream) {
       alert(stream);
     context = new webkitAudioContext();
     analyser = context.createAnalyser();
         canvas = document.getElementById('analyser_render');
     ctx = canvas.getContext('2d');
     source = context.createMediaStreamSource(stream);
     source.connect(analyser); 
     frameLooper();
      },
      function(err) {
         console.log("The following error occurred: " + err.name);
      }
   );
} else {
   console.log("getUserMedia not supported");
}

 

Then I found out that the MediaStreamSource interface of Audio API is not supported yet. Are there any other ways to analyze audio from the mic?

编辑者为: Jackie Li 03 4月, 2017

响应

1 回复
Armaan-Ul- Islam

Yes, there is other way; it's Camera API

 

Please check this API reference here:

https://developer.tizen.org/development/api-references/web-application?redirect=https://developer.tizen.org/dev-guide/3.0.0/org.tizen.web.apireference/html/w3c_api/camera_w.html#createCameraControlidp93720

 

https://developer.tizen.org/development/api-references/web-application?redirect=https://developer.tizen.org/dev-guide/3.0.0/org.tizen.web.apireference/html/w3c_api/camera_w.html#::Camera::CameraMediaRecorder

 

Sample Code (Part): 

 

navigator.webkitGetUserMedia({
    video: false,
    audio: true}, 
    gotStream, noStream);

function gotStream(stream)
{
  navigator.tizCamera.createCameraControl(stream, gotCamera, noCamera);
}

function noStream() {....}

function gotCamera(CameraControl) { 
   // Use CameraControl.recorder
}

function noCamera() {}