开发者

How to listen to microphone and detect sound loudness in Delphi 7

开发者 https://www.devze.com 2023-03-05 01:54 出处:网络
I need a program to catch an event when microphone input gets louder t开发者_Python百科han certain threshold value. So probably I need to constantly listen to mic, and somehow measure sound amplitude?

I need a program to catch an event when microphone input gets louder t开发者_Python百科han certain threshold value. So probably I need to constantly listen to mic, and somehow measure sound amplitude? Is it possible to do that in Delphi 7?


I recommend you to use the BASS Audio Library http://www.un4seen.com/bass.html

BASS is an audio library .. to provide developers with powerful stream (MP3.. OGG.. ) functions. All in a tiny DLL, under 100KB in size.

it's very easy to use, as this simple minimalistic program illustrates. It is based on the BASS Record Test for Delphi, included in the samples that come with BASS. See it for a complete save and playback of the recorded audio.

Just compile it and run it.

program rec;
uses Windows, Bass;

(* This function called while recording audio *)
function RecordingCallback(h:HRECORD; b:Pointer; l,u: DWord): boolean; stdcall;
 var level:dword; 
 begin
  level:=BASS_ChannelGetLevel(h);
  write(''#13,LoWord(level),'-',HiWord(level),'         ');
  Result := True;
 end;

begin
  BASS_RecordInit(-1);
  BASS_RecordStart(44100, 2, 0, @RecordingCallback, nil);
  Readln;
  BASS_RecordFree;
end.


Yes of course. Wave sound is just about that, the amplitude of the sound wave at each moment. Volume is afaik the RMS (root mean square) of the samples.

Just get whatever audio library you use, obtain the wave data and calculate this value. Maybe even simply having a moving average is already enough (sparing you the RMS thing).

Delphi 7 would do fine for this, and comes with mmsystem headers. More advanced components are available (I used the lakeofsoft lib for a while), but that might be overkill, if this is your only audio operation.


I recommend you to look AudioLab

0

精彩评论

暂无评论...
验证码 换一张
取 消