You can consider section 6.c in Handbook: http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=3&chap=6.
There you can hook into Portage process and execute some media player after completing.
Not sure how to check for failed status, but i think, it is possible.


2014-07-14 16:52 GMT+06:00 Andrew Lowe <agl@wht.com.au>:
Hi all,
        I have a laptop churning away in the loungeroom doing an "emerge -NuD
world" whilst I'm in my office, amongst other things composing this
email. If my world update fails, I won't know until I look at the screen
in the other room. Is there a way to get emerge to play a song depending
upon the status of the emerge build?

        If memory serves, an email can be sent letting you know what's
happening, but a sound would be better. For example, on those days when
you kick off an emerge then start pottering around the house doing
stuff. All of a sudden Wagner's "Ride of the Valkyries" starts playing,
and you know the emerge has karked it....

        Thoughts greatly appreciated,

                Andrew