views:

790

answers:

4

Hi,

I have a mosquito problem in my house. This wouldn't usually concern a programmers' community; However, I've seen some devices that claim to deter these nasty creatures by playing a 17Khz tone. I would like to do this using my laptop.

One method would be creating an MP3 with a a single, fixed-frequency tone (This can easily done by audacity), opening it with a python library and playing it repeatedly.

The second would be playing a sound using the computer built-in speaker. I'm looking for something similar to QBasic Sound:

SOUND 17000, 100

Is there a python library for that?

+1  A: 

This seems to be what you are looking for.

Adrian Grigore
+6  A: 

PyAudiere is a simple cross-platform solution for the problem:

>>> import audiere
>>> d = audiere.open_device()
>>> t = d.create_tone(17000) # 17 KHz
>>> t.play() # non-blocking call
>>> import time
>>> time.sleep(5)
>>> t.stop()
J.F. Sebastian
Looks to be a great lib, thanks from my side!
paffnucy
Cool. Can you tell anything about stability issues? The lest release is 0.2.
Adam Matan
@Udi Pasmon: PyAudiere is a simple wrapper for corresponding C++ library http://audiere.sourceforge.net/
J.F. Sebastian
A: 

You can use the Python binding of the SDL (Simple Direct Media Library).

Monkey
+2  A: 

The module winsound is included with Python, so there are no external libraries to install, and it should do what you want (and not much else).

 import winsound
 winsound.Beep(17000, 100)

It's very simple and easy, though is only available for Windows.

tom10
By the way, although this will produce a sound, I really doubt it will deter mosquitoes, in fact, I doubt they could even hear it. The issue is that most insects don't hear using tympanic membranes like we do, but hear using sensory hairs. But sensory hairs are only sensitive to air velocity, not pressure, and by the time you get far from the speaker, it's almost all pressure with very little velocity. That is, they won't hear it unless they are standing right on your speaker.
tom10
So the speaker wold have to be very powerful, and probably not a common PC speaker.Luckily, I am still a student in a science faculty - I will ask an entomologist and post the answer here.
Adam Matan
I'm very interested to hear whether this works. If it does, I've been thinking about these problems wrong for years (which isn't so unlikely). My current perspective is that the air velocity falls off as 1/r^3, which is very fast, and one would need an impossibly loud speaker.
tom10