I am trying to view the spectral slice of a point using the Praat Script. I have successfully generated the slice and moved the cursor to the required point but I don't know how to get the energy value at that point.

Spectrum Slice:

Spectrum Slice generated by script


I have moved to the frequency point 3000 but I want to get its y-axis value (plotted energy value in dB).

Code Till Now:

filePath$ = dirPath$+"/"+fileName$+".wav";
sound = Read from file... 'filePath$'
selectObject: sound

editor: sound
    Move cursor to: number(time_of_slice$)
    View spectral slice

slice$ = "Spectrum " + fileName$ + "_" + time_of_slice$
selectObject: slice$
editor: slice$
    Move cursor to: number(frequency$)

Someone please guide me in this regard. Any kind of help will be highly appreciated.

1 Answer 1


There is no straightforward way for extracting the power in db/Hz from a Spectrum, but you could use this workaround:

form Get db/Hz from Spectrum slice
    comment Enter time in seconds:
    real time 0
    comment Directory of Spectrum list file
    word directory ~/Desktop
    comment List file name
    word file spectrum.txt

To Spectrogram: 0.005, 5000, 0.002, 20, "Gaussian"
To Spectrum (slice): time
list$ = List: "yes", "yes", "no", "no", "no", "yes"
writeFile: "'directory$'/'file$'", list$

The script assumes the sound object is selected (you can modify the code to loop through sounds and/or times).

The time value you see in the form once you run the script in a Praat script window is the time at which you what the spectrum slice.

The output is a tab-delimited .txt file with columns bin, freq(Hz) and pow(db/Hz). The value you are looking after is in the pow(db/Hz) column. You can add code for reading the tab-delimited file back into PRAAT as a Table object and then query that object to get the power value at the desired frequency (it needs a bit of hacking because frequency values are not integers, so, for example, you will probably not be able to find a frequency value of 3000 Hz).

Alternatively you can use other programmes to get the value instead of reimporting the file into PRAAT, like AWK or R, but it's up to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.