If you started the sound file, the yes, you can detect how long it's playing for and when it ends.
If someone else started it, then the closest you can come is to set the sound input to record the sound output, and try to do analysis on the sound you record that way.
Jon Watte, Direct3D MVP
kW X-port 3ds Max .X exporter
kW Animation source code