Fundamental Frequency Estimation is a method for determining the pitch of arbitrary audio input. [sleepwalking] has a library that can do this: https://github.com/Sleepwalking/libpyin