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

杀马特。学长 韩版系。学妹 提交于 2020-01-14 04:17:26

问题


I need a program to catch an event when microphone input gets louder than 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?


回答1:


I recommend you to look AudioLab




回答2:


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.



回答3:


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.



来源:https://stackoverflow.com/questions/5951819/how-to-listen-to-microphone-and-detect-sound-loudness-in-delphi-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!