def seek(wfile, position, end=None):
    """
    Seeks `position` in `wfile`, and returns the number of frames to read until `end`.
    """
    end_frame = wfile.getnframes()
    if end != None:
        end_frame = min(end * wfile.getframerate(), end_frame)
    position_frame = position * wfile.getframerate()
    wfile.setpos(int(round(position_frame)))
    return int(round(end_frame - position_frame))
