question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using AudioWorklet convert volume meter value into decibel

See original GitHub issue

First, thanks for your sharing, I would like to know how to convert volume into decibel by using AudioWorklet. In your AudioWorklet volume meter example, I can get volume value. This link is the example I found https://github.com/GoogleChromeLabs/web-audio-samples/commit/7c109d7d21c24bfa031f843877837e36ea0028cb .

// volume need to * 100 to make sure value between 1 to 10
this._volume = Math.max(rms, this._volume * SMOOTHING_FACTOR) * 100;
 
// I would like to know is this the correct way to convert volume to decibel? 
// My example is 16bits so I divided by 32767
const dB = 10 * Math.log10(this._volume / 32767);  

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
rvadhavkcommented, Sep 16, 2022

I just curious, is this the correct way to get real or close dB value? Or it’s just ratio.

This isn’t my area of expertise, so I could be wrong, but to get the “real” loudness in dB instead of just computing a ratio of current power to max power, I believe you need some reference measurement to know the relationship between the RMS of the actual sound pressure in pascals and the RMS of the unitless PCM data: https://en.wikipedia.org/wiki/Decibel#Acoustics. So unless you can ask your users to play some sort of calibration sound at a known fixed distance from the microphone or you know exactly what microphone they’re using and what the gain is and everything, you can’t know the absolute loudness.

0reactions
Mayviscommented, Sep 21, 2022

This won’t be very reliable. For example with autoGainControl you already can influence this value. The output on MacOs Safari and MacOs Chrome is really different.

I like the approach in this example (I started also with the volume-meter example) better and I assume it’s even less resource intensive.

I prefer to use AudioWorklet instead of using autoGainControl😅. Because I also have to manipulate float32 to int16…etc. I worked on an AI company and build ASR associated project. I know the reliability that you mention. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get microphone volume using AudioWorklet
We need to communicate atleast from AudioWorkletProcessor to AudioWorkletNode the current value or for this example the volume to take any ...
Read more >
Background audio processing using AudioWorklet - Web APIs
This article explains how to create an audio worklet processor and use it in a Web Audio application.
Read more >
Web Audio API - W3C
Abstract. This specification describes a high-level Web API for processing and synthesizing audio in web applications.
Read more >
Pro Audio Plugins | Decibel User Manual - PROCESS.AUDIO
Designed by award-winning engineers, Decibel features an extensive selection of meters in a completely customizable and resizable user interface.
Read more >
Web Audio API - GitHub Pages
A ConstantSourceNode interface, an AudioNode for generating a nominally constant output value with an AudioParam to allow automation of the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found