def waveform_time_to_spec_time(t, spectrogram_len, spectrogram_generator):
    """Converts time in waveform space to time in spectrogram space given parameters of STFT"""

    hop_length, window_length = spectrogram_generator.hop_length, spectrogram_generator.win_length
    for hop in range(spectrogram_len):
        if t <= hop * hop_length + window_length / 2 and t >= hop * hop_length - window_length / 2:
            # As a convention, we will use the first hop that covers t, even though multiple may cover it as well
            return hop