nininigold's picture
Upload folder using huggingface_hub
3cecacc verified
raw
history blame contribute delete
892 Bytes
import librosa
import librosa.display
import numpy as np
import matplotlib.pyplot as plt
# πŸ”Ή μ˜€λ””μ˜€ 파일 λ‘œλ“œ
file_real = "/path/to/real_audio.wav" # Real μ˜€λ””μ˜€ 경둜
file_fake = "/path/to/generative_audio.wav" # AI 생성 μ˜€λ””μ˜€ 경둜
def plot_spectrogram(audio_file, title):
y, sr = librosa.load(audio_file, sr=16000) # μƒ˜ν”Œλ§ 레이트 16kHz
D = librosa.amplitude_to_db(np.abs(librosa.stft(y)), ref=np.max) # STFT λ³€ν™˜
plt.figure(figsize=(10, 4))
librosa.display.specshow(D, sr=sr, x_axis='time', y_axis='hz', cmap='magma')
plt.colorbar(format='%+2.0f dB')
plt.title(title)
plt.ylim(4000, 16000) # 4kHz 이상 고주파 μ˜μ—­λ§Œ ν‘œμ‹œ
plt.show()
# πŸ”Ή Real vs Generative Spectrogram 비ꡐ
plot_spectrogram(file_real, "Real Audio Spectrogram (4kHz+)")
plot_spectrogram(file_fake, "Generative Audio Spectrogram (4kHz+)")