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?
PyAudiere is a simple cross-platform solution for the problem:
pyaudiere.org is gone. The site and binary installers for Python 2 (debian, windows) are available via the wayback machine e.g., here's source code
pyaudiere-0.2.tar.gz
.To support both Python 2 and 3 on Linux, Windows, OSX,
pyaudio
module could be used instead:Example:
It is a modified (to support Python 3) version of this AskUbuntu answer.
You can use the Python binding of the SDL (Simple Direct Media Library).
There is also a very simple way to play a fixed-frequency sound, use:
for example:
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).
It's very simple and easy, though is only available for Windows.
But:
A complete answer to this question should note that although this method will produce a sound, it will not deter mosquitoes. It's already been tested: see here and here
I'm putting my code in here a it helps a programmer gain clarity over how the code works
explanation is in the code itself