import contextlib
import wave


def duration(filename):
    """
    Opens a wave file and finds the number of frames per rate

    :filename:      str()           A filename (relative to __main__)
    :returns:       float()         Duration in seconds
    """

    with contextlib.closing(wave.open(filename, 'r')) as data:
        frames = data.getnframes()
        rate = data.getframerate()
        return frames / float(rate)