Exporting Audio Level Values

Audacity visualizes a loaded audio track as a wave form, i.e. level values (y axe) along time (x axe). Can these values be exported, e.g. in a file? Or accessed via an API?

I would use these values for subsequent audio analyses.

Short answer: Yes. You can write a Nyquist script to export the amplitude values.


Longer answer:
As you zoom in on a track, you will see the amplitude in increasing detail, until you eventually see individual “samples”.




Each “dot” represents the amplitude of the waveform at a point in time. The track “sample rate” (typically 44100) is the number of “samples” per second.
At this resolution, even a short audio selection will generate a lot of data. Just 23 seconds will give you over a million data points (enough to crash some text editors).

Audacity includes a tool to export sample values, but should generally be used with short audio selections so as to avoid creating unreasonable amounts of data: Sample Data Export - Audacity Manual


To reduce the amount of data, you could look at the peak value, or average value over a larger period of time. For example, running this code in the Nyquist Prompt effect will display the “absolute peak” value for each second of selected audio in a mono track:
(“absolute peak” ignores the +/- sign)

;version 4
;debugflags trace

(defun analyze (sig step)
  (let ((data (snd-avg sig step step op-peak)))
    (setf *track* nil)  ;release *track* variable to conserve memory
    (do ((val (snd-fetch data) (snd-fetch data)))
        ((not val) "")
      (print val))))

(setf step (round *sound-srate*)) ;number of samples in 1 second
(cond
  ((arrayp *track*) "Error.\nMono tracks only.")
  ((< len *sound-srate*) "Error.\nSelection must be at least 1 second")
  (t (analyze *track* step)))

Thank you for the answer, it works perfectly!