Getting audio input and processing it?
d at davea.name
Thu Jan 10 06:46:55 CET 2013
On 01/09/2013 07:20 PM, Michael Curry wrote:
> I've been working on a Morse Code translator, I've made it work so that you can input English and it will translate it to Morse and play the Audio. I now want to add a feature to the program that takes audio input, processes it and then outputs the English.
> Are there any specific APIs that I can use to take input from a microphone, is there any way to detect frequencies or amplitudes, as well as find out for how long the wave lasts? If not, are there any implementations of this? Would there be a way to do it?
If you find an approach that gets audio information from your hardware,
and on your operating system, then you presumably end up with a stream
of bytes (or of some other data type, if the sample size is bigger than
8 bits). If this were my project, I'd ignore the detecting of frequency
(though it can be done, by various filtering techniques), and just
measure energy. Presumably the signal is quiet for space, and noisy for
mark. So you set a threshold, and measure how long the signal is below
the threshold, and then how long it's above. The time above the
threshold is how long the "wave lasts." Presumably you can then set a
few length thresholds, and short values are dit and longer ones are dah.
So, how do you measure energy on a byte string? The way I've seen audio
encoded in 8 bits has 128 as the DC zero reference point. Values above
and below that represent a nonzero signal voltage. So you'd do
to get an instantaneous energy. Do a sanity check to make sure the
"quiet" signal gives you a very small energy (some noise expected, of
There are lots of refinements possible. But I suspect someone else is
going to pop in and say that libary xyz on pypi will do it all for you
automatically. There's probably someone who's done the whole project
before. But what's the fun in that?
More information about the Python-list