PANDUAN Audio AI

Spektogram Mel

A mel spectrogram is a picture of sound: it shows how much energy an audio signal has in each of a few dozen frequency bands, frame by frame over time, with the bands spaced on the mel scale so that low frequencies get finer detail, roughly as human hearing does.

Dengarkan panduan iniDiceritakan oleh AI · ~8 min

Di halaman ini9 menit baca
  1. Ikhtisar
  2. Poin-poin utama
  3. Menyelam Lebih Dalam
  4. Computing a Whisper-style mel spectrogram of a test tone
  5. Implementasi Dunia Nyata
  6. Masa Depan Spektogram Mel
  7. Mempraktikkannya
  8. Sumber dan bacaan lebih lanjut
  9. Terus Menjelajah
  10. Pertanyaan yang sering diajukan

Ikhtisar

It is the standard input to speech recognizers such as Whisper and the standard intermediate output of text-to-speech systems such as Tacotron 2.

Poin-poin utama

  1. A mel spectrogram shows audio energy per frequency band over time, with bands spaced on the perceptual mel scale.
  2. The mel scale comes from a 1937 study by Stevens, Volkmann and Newman in the Journal of the Acoustical Society of America.
  3. The HTK mel formula is 2595 times log10(1 + f/700), which maps 1,000 Hz to about 1,000 mels.
  4. Whisper uses 80-channel log-mel input on 25 ms windows with a 10 ms stride, and Whisper large-v3 uses 128 bins.
  5. Mel spectrograms discard phase, so turning them back into audio requires a vocoder such as WaveNet or HiFi-GAN.
  6. Sample rate, FFT size, hop, band count, frequency range and mel formula must all match what a model was trained on.

Menyelam Lebih Dalam

A mel spectrogram is a two-dimensional array that describes a sound. One axis is time, divided into short overlapping frames. The other axis is frequency, divided into bands. Each cell holds the energy of the sound in that band during that frame. What makes it a mel spectrogram, rather than an ordinary spectrogram, is how the bands are spaced. They follow the mel scale, a perceptual pitch scale on which equal steps sound roughly equally far apart to a listener. On that scale low frequencies are spread out and high frequencies are squeezed together, so a mel spectrogram spends most of its resolution where speech and music carry the most perceptually important detail. Researchers usually take the logarithm of the energies, producing a log-mel spectrogram, because loudness perception is also roughly logarithmic.

Computing one takes four steps. First, the waveform, a list of air-pressure samples such as 16,000 per second, is cut into frames using a window function, typically a Hann window that tapers each frame's edges. The window length sets frequency resolution and the hop, the gap between frame starts, sets time resolution. Second, each frame goes through a short-time Fourier transform (STFT), which measures how much of each frequency is present, producing a linear spectrogram with n_fft/2 + 1 frequency bins. Third, the magnitudes, or their squares for power, are multiplied by a mel filterbank: a set of overlapping triangular filters, each centered on a point evenly spaced on the mel scale, which pool neighboring frequency bins into one band. Fourth, a logarithm compresses the dynamic range, usually after clipping very small values so the log does not explode.

The scale itself comes from psychology. In 1937 S. S. Stevens and J. Volkmann of Harvard and E. B. Newman of Swarthmore published "A Scale for the Measurement of the Psychological Magnitude Pitch" in the Journal of the Acoustical Society of America. They built a subjective pitch scale by asking listeners to judge when one tone sounded half as high as another, at many reference frequencies. Two engineering formulas descended from that work. The HTK formula, named after the Hidden Markov Model Toolkit and the default in torchaudio, is mel = 2595 times log10(1 + f/700), which maps 1,000 Hz to about 1,000 mels. The Slaney formula from Slaney's MATLAB Auditory Toolbox, the default in librosa, is linear below 1,000 Hz and logarithmic above. They give different band edges, so features computed one way do not match a model trained the other way.

Mel features have been used for speech recognition for decades, as the Tacotron 2 paper notes, but deep learning made them a common interface between models. Tacotron 2, posted by Google researchers in December 2017, split text-to-speech into two networks connected by a mel spectrogram: one predicts 80-channel mel frames from characters, and a modified WaveNet vocoder, the network that turns spectral features back into a waveform, generates audio from them. The authors used 50 ms frames, a 12.5 ms hop, a filterbank from 125 Hz to 7.6 kHz, and clipped magnitudes at 0.01 before taking the log. They reported a mean opinion score of 4.53, against 4.58 for professional recordings. HiFi-GAN in 2020 made the vocoder step fast, and Whisper in 2022 trained a speech recognizer on 680,000 hours of audio using 80-channel log-mel input.

The main alternatives each trade something. A raw waveform keeps everything, including phase, but is long and hard to model directly: 30 seconds at 16 kHz is 480,000 numbers, while Whisper's mel representation of the same audio is 3,000 frames of 80 values, half as many numbers arranged in a far more structured form. A linear-frequency STFT spectrogram keeps more high-frequency detail and can be roughly inverted with the Griffin-Lim algorithm, but uses many more frequency bins. Mel-frequency cepstral coefficients (MFCCs), made by applying a further cosine transform to the log-mel bands, compress further and were the classic input to older recognizers. Learned audio tokenizers produce discrete codes instead of a fixed transform. The Tacotron 2 paper's argument for mel is that it is easy to compute from audio, smoother than raw samples, and indifferent to phase within each frame, which makes squared-error training easier.

Those same properties are the limitations. A mel spectrogram discards phase, and the Tacotron 2 authors note that it discards even more information than a linear spectrogram, so turning it back into audio is a hard inverse problem that needs a trained vocoder or an approximation. The pooling of high frequencies blurs detail that matters for some tasks, such as fricative sounds, music cymbals or non-speech signals; Tacotron 2's authors explicitly accepted this trade, arguing that high-frequency noise bursts rarely need high fidelity for intelligibility. Settings matter: Tacotron 2's authors tried a 5 ms hop and found that the extra time resolution caused significantly more pronunciation problems. A mel spectrogram is also not a transcript, a pitch track or a quality score; it is a signal representation that a model must still interpret.

In practice the transform is cheap and the configuration is the hard part. Every model expects a specific sample rate, FFT size, window length, hop, number of mel bands, frequency range, mel formula, normalization and log scaling, and mismatching any of them silently degrades results. Whisper large-v3, for example, needs 128 bands where earlier Whisper models used 80, and HiFi-GAN's published setup uses an FFT size of 1,024 and a hop of 256 samples at 22.05 kHz. The safest approach is to use the feature extractor shipped with a model rather than reimplementing it.

04Contoh yang berhasil

Computing a Whisper-style mel spectrogram of a test tone

  1. Generate one second of a 440 Hz sine wave at 16,000 samples per second, giving 16,000 samples.

  2. Create torchaudio.transforms.MelSpectrogram with sample_rate 16000, n_fft 400, hop_length 160, n_mels 80 and f_max 8000.

  3. Apply it to the tone; with the default centered frames the output shape is 80 bands by 101 frames.

  4. Take the log of the output after clamping values below a small epsilon such as 1e-10.

  5. Find the band with the most energy: 440 Hz is about 550 mels on the HTK scale, which falls between the centers of filters 14 and 15 when counting from zero.

  6. Plot the result as an image with time on the x-axis and mel band on the y-axis, then repeat with a 4,000 Hz tone and compare how wide its band is.

Apa yang ditunjukkannya

An 80 by 101 log-mel array with a bright horizontal line near band 15 for the 440 Hz tone. Check it by confirming the frame count equals 1 + 16000 // 160 and by seeing that the 4,000 Hz tone lands in a much wider band higher up the image.

Implementasi Dunia Nyata

OpenAI's Whisper converts all audio to 16 kHz and computes an 80-channel log-magnitude mel spectrogram on 25 ms windows with a 10 ms stride before the transformer encoder sees it.

Whisper large-v3 changed its input to 128 mel frequency bins instead of 80, according to its Hugging Face model card, while keeping the rest of the architecture the same.

Google's Tacotron 2 predicts 80-channel mel spectrograms spanning 125 Hz to 7.6 kHz from text, and a modified WaveNet turns them into audio, reaching a mean opinion score of 4.53.

HiFi-GAN converts 80-band mel spectrograms into 22.05 kHz speech 167.9 times faster than real time on one V100 GPU, and its training loss compares mel spectrograms of real and generated audio.

Audio libraries expose the transform directly: torchaudio's MelSpectrogram defaults to 128 mel filters and the HTK mel formula, while librosa defaults to the Slaney Auditory Toolbox version.

Masa Depan Spektogram Mel

Mel spectrograms remain the default front end for many speech systems, but research keeps testing their limits. Whisper large-v3's move from 80 to 128 mel bins shows that even well-established configurations are still being tuned, and its model card reports 10% to 20% fewer errors than large-v2 across many languages, although that release also changed training data, so the gain cannot be attributed to the input alone. On the generation side, the two-stage text-to-mel then mel-to-waveform pipeline described in the Tacotron 2 and HiFi-GAN papers is now one of several designs. Some speech and music systems instead model discrete codes from neural audio codecs or work on raw waveforms directly, which avoids the phase-loss problem but brings its own costs. Open questions include how much information a fixed mel transform throws away for non-speech audio, whether learned front ends consistently beat it, and how to keep preprocessing reproducible when small configuration differences change model behavior. Published ablations, like Tacotron 2's test of frame hop, remain the reliable way to judge those choices.

Mempraktikkannya

Mengapa itu penting

  • Akses dan jangkauan. Ini meningkatkan aksesibilitas melalui transkripsi, narasi, dan antarmuka suara.
  • Biaya dan anggaran. Tim media dapat mengirimkan audio yang bagus lebih cepat dengan anggaran lebih kecil.
  • Kecepatan dan skala. Sistem yang berhubungan dengan pelanggan dapat memproses interaksi lisan dalam skala yang lebih besar.

Hati-hati

  • Risiko penyalahgunaan suara dan peniruan identitas meningkat jika tidak ada persetujuan.
  • Akurasi dapat menurun pada aksen, dialek, atau lingkungan yang bising.
  • Audio sintetis dapat disalahartikan sebagai ucapan asli tanpa label yang jelas.

Langkah selanjutnya

  1. Dapatkan persetujuan eksplisit untuk pengambilan suara, kloning, dan penggunaan kembali.
  2. Uji kualitas di beragam speaker dan kondisi latar belakang.
  3. Tentukan kapan manusia harus meninjau atau menyetujui keluaran.
  4. Beri label pada audio sintetis dan simpan catatan asalnya untuk akuntabilitas.

Sumber dan bacaan lebih lanjut

  1. Journal of the Acoustical Society of America (1937)A Scale for the Measurement of the Psychological Magnitude Pitch
  2. arXiv (Google)Natural TTS Synthesis by Conditioning WaveNet on Mel Spectrogram Predictions
  3. arXiv (OpenAI)Pengenalan Ucapan yang Kuat melalui Pengawasan Lemah Berskala Besar
  4. Hugging Faceopenai/whisper-large-v3 model card
  5. arXiv (NeurIPS 2020)HiFi-GAN: Generative Adversarial Networks for Efficient and High Fidelity Speech Synthesis
  6. PyTorch documentationtorchaudio.transforms.MelSpectrogram
  7. librosa documentationlibrosa.mel_frequencies

Terus Menjelajah

Buletin gratis

Dapatkan pengarahan AI harian

Tiga cerita AI terverifikasi setiap pagi hari kerja, ditulis dalam bahasa Inggris sederhana. Gratis selamanya, tanpa iklan.

Satu email setiap hari kerja. Berhenti berlangganan dalam satu klik. Kami tidak pernah menjual atau membagikan alamat Anda.

Uji diri Anda sendiri

Take the Mel Spectrograms quiz

Umpan balik instan untuk setiap jawaban, dan sertifikat yang dapat dibagikan dengan ID yang dapat diverifikasi setelah Anda lulus kursus.

Mulai kuis

Mendukung pendidikan AI gratis. AI Understanding adalah organisasi nirlaba 501(c)(3) — tanpa iklan, tanpa paywall, selamanya. Berikan sumbangan

Pertanyaan yang sering diajukan

What is Mel Spectrograms?

A mel spectrogram is a picture of sound: it shows how much energy an audio signal has in each of a few dozen frequency bands, frame by frame over time, with the bands spaced on the mel scale so that low frequencies get finer detail, roughly as human hearing does. It is the standard input to speech recognizers such as Whisper and the standard intermediate output of text-to-speech systems such as Tacotron 2.

Apa yang diwakili oleh spektogram mel?

A mel spectrogram maps spectral energy across time into mel-frequency bands.

What is the mel scale designed to represent?

Mel-frequency representations use a nonlinear frequency scale for audio analysis; the classic Davis–Mermelstein study evaluated mel-based features for speech recognition.

What transform is commonly used to obtain short-frame frequency content before mel filtering?

The librosa mel-spectrogram function computes a spectrogram from audio before mapping it to mel bands.

Why may a power spectrogram be converted to decibel units?

librosa power_to_db converts power values to decibels with a logarithmic ratio to a reference.

Which parameter controls the number of mel-frequency bands in librosa?

The librosa API lists n_mels as the number of mel bands to generate.