| 1 |
# test/manually/Sound_to_Spectrogram.praat |
| 2 |
# Paul Boersma, 12 August 2025 |
| 3 |
|
| 4 |
timeStep = 0.001 ; seconds |
| 5 |
sound1000 = Create Sound from formula: "sineWithNoise", 1, 0, 1000, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,1)" |
| 6 |
stopwatch |
| 7 |
spectrogram1000 = noprogress To Spectrogram: 0.005, 5000.0, timeStep, 20.0, "Gaussian" |
| 8 |
writeInfoLine: stopwatch |
| 9 |
sound100 = Create Sound from formula: "sineWithNoise", 1, 0, 100, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,1)" |
| 10 |
stopwatch |
| 11 |
spectrogram100 = noprogress To Spectrogram: 0.005, 5000.0, timeStep, 20.0, "Gaussian" |
| 12 |
appendInfoLine: stopwatch |
| 13 |
sound10 = Create Sound from formula: "sineWithNoise", 1, 0, 10, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,1)" |
| 14 |
stopwatch |
| 15 |
spectrogram10 = noprogress To Spectrogram: 0.005, 5000.0, timeStep, 20.0, "Gaussian" |
| 16 |
appendInfoLine: stopwatch |
| 17 |
sound1 = Create Sound from formula: "sineWithNoise", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,1)" |
| 18 |
stopwatch |
| 19 |
spectrogram1 = noprogress To Spectrogram: 0.005, 5000.0, timeStep, 20.0, "Gaussian" |
| 20 |
appendInfoLine: stopwatch |
| 21 |
sound01 = Create Sound from formula: "sineWithNoise", 1, 0, 0.1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,1)" |
| 22 |
stopwatch |
| 23 |
spectrogram01 = noprogress To Spectrogram: 0.005, 5000.0, timeStep, 20.0, "Gaussian" |
| 24 |
appendInfoLine: stopwatch |
| 25 |
|
| 26 |
removeObject: sound01, sound1, sound10, sound100, sound1000, spectrogram01, spectrogram1, spectrogram10, spectrogram100, spectrogram1000 |
| 27 |
|
| 28 |
margin = 0.0095 ; seconds |
| 29 |
numberOfReplications = 100 |
| 30 |
maximumNumberOfFrames = 100 |
| 31 |
numberOfTimings = numberOfReplications * maximumNumberOfFrames |
| 32 |
time# = zero# (maximumNumberOfFrames) |
| 33 |
numbersOfFrames# = shuffle#: repeat# (to# (maximumNumberOfFrames), numberOfReplications) |
| 34 |
for timing to numberOfTimings |
| 35 |
desiredNumberOfFrames = numbersOfFrames# [timing] |
| 36 |
durationOfFrames = desiredNumberOfFrames * timeStep |
| 37 |
durationOfSound = durationOfFrames + margin |
| 38 |
sound = Create Sound from formula: "sineWithNoise", 1, 0, durationOfSound, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,1)" |
| 39 |
stopwatch |
| 40 |
spectrogram = noprogress To Spectrogram: 0.005, 5000.0, timeStep, 20.0, "Gaussian" |
| 41 |
time# [desiredNumberOfFrames] += stopwatch |
| 42 |
resultingNumberOfFrames = Get number of frames |
| 43 |
assert resultingNumberOfFrames = desiredNumberOfFrames ; 'desiredNumberOfFrames' 'resultingNumberOfFrames' |
| 44 |
removeObject: sound, spectrogram |
| 45 |
endfor |
| 46 |
|
| 47 |
for numberOfFrames from 1 to maximumNumberOfFrames |
| 48 |
appendInfoLine: numberOfFrames, " ", round (time# [numberOfFrames] / numberOfReplications * 1e6), "μ" |
| 49 |
endfor |
| 50 |
|
| 51 |
appendInfoLine: "Mean: ", round (mean (time#) / numberOfReplications * 1e6), "μ" |