Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

david.cherrie

macrumors newbie
Original poster
Jun 17, 2015
7
0
Hi everyone,

I'm trying to get a decibel value from an audio source of the built-in microphone for a Mac. I know there are so many different iOS apps and OS X apps but they don't allow me to actually get a live export of that number.

The ideal scenario is that we have some way of getting a numerical value in a decibel range into a program we use via AppleScript. We just need to convert what a microphone hears to a decibel numerical value.

I have found a few websites that are on topic but I have no idea how to use Xcode as its not as simple as AppleScript.

http://b2cloud.com.au/tutorial/obtaining-decibels-from-the-ios-microphone/

http://stackoverflow.com/questions/9247255/am-i-doing-the-right-thing-to-convert -decibel-from-120-0-to-0-120

Any help is appreciated!

Cheers,

David
 
Last edited:
It's going to depend on the microphone you use. The only reason they can do this on the iPhone is that they have calibrated the readings for the iPhone microphone.
 
It doesn't need to be accurate. There are apps that you can download from the App Store for your Mac that are decibel readers. I just need a numerical value that increases when the sound gets louder and drops when it gets quiet. It could be a value between 0.000 and 1.000. I can then use a maths equation to then get up to a range from 10db to 140db. I just need a changing value that changes because of how loud and soft it gets that I can then put into Apple Script.
 
It sounds like you're just looking for the raw PCM data in the audio. You can get the amplitude of the sound (if it's 16-bit sound it will be +32768/-32767) if you hunt around in AudioFileReadPacketData
 
I have never done audio programming on the Mac. But according to the CoreAudio docs for the Mac, the appropriate type of object seems to be an AudioQueue to record sound from a microphone. There is an AudioQueueSetParameters function which allows the volume to be modified. The docs also talk about a property called "kAudioQueueProperty_CurrentLevelMeterDB" that can be queried that returns RMS power which seems to be what the O.P. is looking for. So if you can figure out how to get audio into a program using an AudioQueue, it seems pretty easy to query the sound level.
 
  • Like
Reactions: robvas
Hi,

I think that if you're wanting to stay with AppleScript and out of Xcode then your only chance is to find an AppleScriptable audio recording app with support for the feature you're asking for. It may exist, but I think it's a longshot.

However, if you're willing to dip your toes into Xcode and Objective-C then its relatively straightforward. I managed to knock up an extremely decibel meter from scratch using mostly code from this tutorial:

http://www.whatsoniphone.com/blog/tutorial-detecting-when-a-user-blows-into-the-mic/

...I know it's iOS, but it worked fine on OS X. I have no idea how accurate it is (I suspect not very!), but it certainly goes up and down with volume. Happy to share my Xcode project with you if that's any help.
 
It doesn't need to be a prerecorded file. You will not be able to do this from Applescript though afaik. For the scale, just don't use a dB scale but any arbitrary scale say from 0 - 100 and skip the units. You'd probably still need to calibrate it so that 100 is very hard to reach but not impossible though. All of this this is also going to depend on where you place the mic and any amplification before the computer obviously.

You could use dBfs for a relative scale, which for a 24 bit sample would go from -144 to 0 dBfs, each bit representing 6 dB. But for your application that wouldn't make much sense, so just go for an arbitrary scale perhaps from "rediculous" to "insane" or something like that. :D
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.