Reading "beats" from a Phone Piezo pin port

I would like to read the beat from a port of a phone where it was a piezo attached ( ringtones one ) and convert to a "comand" , for example:

if i call ringtone1 = turn on relay
if i send sms ringtone2= turn off relay

Is there any way that this reading sohould be done in particular? There is any sketch that could be usefull?

Thanks.