There are a few ways of telling, especially from the sounds they make, If you hear it making a sound sort of like purring this means it is enjoying itself maybe because you are petting it or while grooming itslef. If it whistles this can also mean it is excited. Wikipedia has sampled the sounds the guinea pigs made and has the meaning of each one, here is a link:
http://en.wikipedia.org/wiki/Guinea_pig#Behavior