How get sound input from microphone in python, and process it on the fly?

前端 未结 3 906
南旧
南旧 2020-11-27 10:30

Greetings,

I\'m trying to write a program in Python which would print a string every time it gets a tap in the microphone. When I say \'tap\', I mean a loud sudden n

3条回答
  •  醉酒成梦
    2020-11-27 10:58

    ...and when I got one how to process it (do I need to use Fourier Transform like it was instructed in the above post)?

    If you want a "tap" then I think you are interested in amplitude more than frequency. So Fourier transforms probably aren't useful for your particular goal. You probably want to make a running measurement of the short-term (say 10 ms) amplitude of the input, and detect when it suddenly increases by a certain delta. You would need to tune the parameters of:

    • what is the "short-term" amplitude measurement
    • what is the delta increase you look for
    • how quickly the delta change must occur

    Although I said you're not interested in frequency, you might want to do some filtering first, to filter out especially low and high frequency components. That might help you avoid some "false positives". You could do that with an FIR or IIR digital filter; Fourier isn't necessary.

提交回复
热议问题