test_audio.py 571 B

12345678910111213141516171819
  1. import os.path
  2. import numpy as np
  3. from whisper.audio import SAMPLE_RATE, load_audio, log_mel_spectrogram
  4. def test_audio():
  5. audio_path = os.path.join(os.path.dirname(__file__), "jfk.flac")
  6. audio = load_audio(audio_path)
  7. assert audio.ndim == 1
  8. assert SAMPLE_RATE * 10 < audio.shape[0] < SAMPLE_RATE * 12
  9. assert 0 < audio.std() < 1
  10. mel_from_audio = log_mel_spectrogram(audio)
  11. mel_from_file = log_mel_spectrogram(audio_path)
  12. assert np.allclose(mel_from_audio, mel_from_file)
  13. assert mel_from_audio.max() - mel_from_audio.min() <= 2.0