Wednesday, November 29, 2006

Sound Detection using C#

I few weeks ago I needed to detect sound through a microphone. What I wanted to do was turn on a computer screen when a sound was heard (talking, clapping etc). After a long google session, all I turned up were several expensive sound detection systems and a piece of VB6 code which sets up the soundcard for sampling using the Win32 API.

Instead of porting all the API code to C#, and having an 'interesting' history with VB6 (who doesn't), I hacked the VB6 code into a dll. This library now provides a list of available recording devices, listens to the microphone and raises an event when the volume is greater than a given threshold. And best of all its easily accessible from .NET code.

Internally, it
  • Grabs a buffer of 8-bit samples from the soundcard. 8-bit means each sample value is 0-256, with 127 being silence.
  • Loops through the buffer, and if there is a value greater than the threshold, raise an event

Get the Detector library (+ source + sample C# application)
Feel free to use it in your own projects. Enjoy!


Anonymous said...

Unlimited Earnings Potential -

Our company is rapidly growing and offers you an extraordinary income helping others succeed. The primary requirement is to follow up on client inquiries and point them in the right direction. It is stress free, rewarding and straightforward work.

For complete details:

(Please feel free to delete this post if you don't want it on your blog. Thanks for the informative blog and opportunity to post.)

Free Webmail Program said...

Webmail program for the major free email sites -

My Mail 1.0 is configured to work with AOL, Gmail, Hotmail, Linuxmail, and Yahoo. With My Mail 1.0 you get the benefit of premium services without having to pay site fees. My Mail 1.0 completely automates the process of sending and receiving mail from the major sites, saving you time and trouble.

My Mail 1.0 eliminates the need to visit web sites to send and receive mail, which increases the speed of sending and receiving email by over 80%, even if they do not offer what is known as POP3, IMAP and SMTP. My Mail 1.0's look is also fully customizable. One you use it, you'll never want to go back to the web site again to get your mail.

For complete details:

(Please feel free to delete this post if you don't want it on your blog. Thanks for the informative blog and opportunity to post.)

HeadBug said...

Hi, I'm interested in capturing audio myself and downloaded your solution, but the Reference to Detector is broken. How do I fix that? Referencing Interop.Detector.dll or Interop.SoundDetector.dll made the program compile with error 80040154:

Retrieving the COM class factory for component with CLSID {C153004D-7066-465E-8C04-B94124A88595} failed due to the following error: 80040154.

Any clues would be nice :)


Kleanthis said...

Hi I have the same problem as Jonas. I get "Retrieving the COM class factory for component with CLSID {C153004D-7066-465E-8C04-B94124A88595} failed due to the following error: 80040154"

Ca you help?


Christopher said...

If you're getting the COM error, it's because you only have the Interop.Detector.DLL in the bin\Debug directory, and not the actual Detector.DLL file.

I noticed the Detector.DLL did not appear to be in the package. You'll want to unzip the, open the project in Visual Basic 6 and do a File-> Make Detector.dll, then add a reference to the .NET application to this DLL and everything should work fine.

Janzour said...

Hi Jeff,

In your Sound detector library, when I load your project, there was a reference to "Detector" that is not found. Do you know where it is?


Anonymous said...

black mold exposureblack mold symptoms of exposurewrought iron garden gatesiron garden gates find them herefine thin hair hairstylessearch hair styles for fine thin hairnight vision binocularsbuy night vision binocularslipitor reactionslipitor allergic reactionsluxury beach resort in the philippines

afordable beach resorts in the philippineshomeopathy for big with great mineral makeup bargainsmineral makeup wholesalersprodam iphone Apple prodam iphone prahacect iphone manualmanual for P 168 iphonefero 52 binocularsnight vision Fero 52 binocularsThe best night vision binoculars here

night vision binoculars bargainsfree photo albums computer programsfree software to make photo albumsfree tax formsprintable tax forms for free craftmatic air bedcraftmatic air bed adjustable info hereboyd air bedboyd night air bed lowest pricefind air beds in wisconsinbest air beds in wisconsincloud air beds

best cloud inflatable air bedssealy air beds portableportables air bedsrv luggage racksaluminum made rv luggage racksair bed raisedbest form raised air bedsbed air informercialsbest informercials bed airmattress sized air beds

bestair bed mattress antique doorknobsantique doorknob identification tipsdvd player troubleshootingtroubleshooting with the dvd playerflat panel television lcd vs plasmaflat panel lcd television versus plasma pic the bestadjustable bed air foam The best bed air foam

hoof prints antique equestrian printsantique hoof prints equestrian printsBuy air bedadjustablebuy the best adjustable air bedsair beds canadian storesCanadian stores for air beds

migraine causemigraine treatments floridaflorida headache clinicdrying dessicantair drying dessicantdessicant air dryerpediatric asthmaasthma specialistasthma children specialistcarpet cleaning dallas txcarpet cleaners dallascarpet cleaning dallas

vero beach vacationvero beach vacationsbeach vacation homes veroms beach vacationsms beach vacationms beach condosmaui beach vacationmaui beach vacationsmaui beach clubbeach vacationsyour beach vacationscheap beach vacations

bob hairstylebob haircutsbob layeredpob hairstylebobbedclassic bobCare for Curly HairTips for Curly Haircurly hair12r 22.5 best pricetires truck bustires 12r 22.5

washington new housenew house houstonnew house san antonionew house venturanew houston house houston house txstains removal dyestains removal clothesstains removalteeth whiteningteeth whiteningbright teeth

jennifer grey nosejennifer nose jobscalebrities nose jobsWomen with Big NosesWomen hairstylesBig Nose Women, hairstyles

calina said...


I have tried your application (Sound detection in c#) and I've got the same error : Retrieving the COM class factory for component with CLSID {C153004D-7066-465E-8C04-B94124A88595}.I saw that the Detector reference is missing.Can you tell how can I solve this problem?I don't know VB6. Thanks

imran said...

hi i am unable to dl your files