Languages

Menu
Sites
Language
Measure decibel or sound level from microphone input.

Hello

I have some problem about measure decibel from microphone input.

What I have to do is recording start when detected lound sound.

So first, I tested audio recording sample code, and modified some part in audio.js 

modified code in audio.js:

function registerStream(mediaStream) {
            navigator.tizCamera.createCameraControl(
                mediaStream,
                onAudioControlCreated,
                onAudioControlError
            );
            //This is modified section.
            var audioContext = new window.webkitAudioContext();
            var analyser = audioContext.createAnalyser();
            var mic = audioContext.createMediaStreamSource(mediaStream);
            var javascriptNode = audioContext.createScriptProcessor(2048,1,1);
            
            analyser.smoothingTimeConstant = 0.8;
            analyser.fftSize = 1024;
            
            mic.connect(analyser);
            analyser.connect(javascriptNode);
            javascriptNode.connect(audioContext.destination);
            
            javascriptNode.onaudioprocess = function(){
                var array = new Uint8Array(analyser.frequencyBinCount);
                analyser.getByteFrequencyData(array);
                var values = 0;
                var length = array.length;
                for(var i=0; i < length; i++){
                    values += (array[i]);
                }
                var average = values / length;
                console.log(average);
            }
            /////
        } 

But any console log can't see.

Any problem in my code?

My question is webkitAudioContext() is not supported in tizen?

And, Any other method to measure decibel or sound level? or Is it impossible in web app?   

Thanks in advance.

Edited by: 은성 부 on 03 May, 2017
View Selected Answer

Responses

6 Replies
Mark as answer
André Reus

hi

To check if your device supported or not use this code

    try {
        // Fix up for prefixing
        alert('Web Audio API is  supported in this browser');
        window.AudioContext = window.AudioContext||window.webkitAudioContext;
        context = new AudioContext();
    }
    catch(e) {
        alert('Web Audio API is not supported in this browser');
    }

And here is  a great docs of Audio API of HTML5

https://www.html5rocks.com/en/tutorials/webaudio/intro/

Rodrigo Morbach

Version 2.3.2 of Tizen seems to support AudioContext. However, I'am not able to use getFloatTimeDomainDate of AnalyzerNode.

André Reus

In my case, Gear S3 shows 

Web Audio API is not supported in this browser
Slawek Kowalski

webkitAudioContext() is supported in Web API but will not able to get source data (not supported by Tizen yet). You need it to calcuatle sound parameters. I am affraid you have to use Native API. More here https://developer.tizen.org/dev-guide/2.4/org.tizen.tutorials/html/native/multimedia/audio_io_tutorial_n.htm#async_rec

Rodrigo Morbach

Hello Slawek, thanks for your reply.

Actually, I don't need to record voice. I am using Speech-to-Text native API, running as a service, and I would like to provide some visual feedback to the user as the recognition start.

There is this sample https://developer.tizen.org/development/sample/web/Multimedia/Voice_Recorder which uses CameraControl API to record user's voice. It makes use of getUserMedia HTML5 API in order to create a microphone Stream.

I followed the section Sound visualization of this article https://developer.tizen.org/community/tip-tech/advanced-web-audio-api-usage in order to draw waves or bar to the user. However, the provided code seems to work only for Mobile devices, and I need to make this work in Gear S3.

Any clue about how to do that?

 

 

 

 

Slawek Kowalski

As I said you can't. There is not supported method to get source data on Gear serie. You need tha data to show visual bar. I researched it a year ago. Maybe it will work for Tizen 3.0. I don't know.