Skip to content

Instantly share code, notes, and snippets.

@tnearey
Last active May 19, 2018 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tnearey/95a09c47bac19bcdc6ce4741ef14ad03 to your computer and use it in GitHub Desktop.
Save tnearey/95a09c47bac19bcdc6ce4741ef14ad03 to your computer and use it in GitHub Desktop.
Praat Script for variable pre-emphasis of audio file: For DIY Laurel-Yanni like exploration
# dbPer8vaLaurelYari.praat
# A riff on the YANNI LAUREL meme of mid May 2018
# Copyleft TM Nearey 2018
# Version 1.1 19 May 2018 adds some bells and whistles to 18 May version
nocheck select all
nocheck Remove
# Set showStimuli to 1 if you want to browse the stimuli manually in Sound Editor
showStimuli=0
# doStaircase=1 will run a 1 up 1 down set of staircase trials with increasing/cecreasing dB per octave tile
doStaircase=1
# cutoff1 is frequency above which k-dB per octave preemphasis will start
cutoff1=1000
# Ver 2.0 Preemphasis is clamped at cutoff2 Hz to avoid overemphasis hf aliasing and noise
cutoff2= 10000
# nEmphasisSteps - at default 20 this goes from 0 dB to 19 dB per octave boost above cutoff1 frequency in 1 dB/oct steps
nEmphasisSteps= 20
# Set noise test to 1 for display of slope per octave to make sure thats about right
noiseTest = 0
nResp=0
startLow=1
soundFilename$="./laurelVocabularyScaled.wav"
lowTargetLabel$="LAUREL"
highTargetLabel$="YANNI"
beginPause: "Setup"
comment: "Change sound file if desired"
text: "SoundFilename", soundFilename$
comment: "Change names of low and high target words if desired"
word: "LowTargetLabel", lowTargetLabel$
word: "HighTargetLabel", highTargetLabel$
boolean: "DoStaircase", doStaircase
comment: "StartLow - start at low end ( original deeper voice), otherwise at high"
boolean: "StartLow" , startLow
comment: "Cutoff 1 is where pre-empasis starts"
positive: "Cutoff1",cutoff1
comment: "Cutoff 2 is where pre-empasis stops changing"
positive: "Cutoff2",cutoff2
comment: "If NoiseTest is set, then staircase is not done and stimuli are shown"
boolean: "NoiseTest", noiseTest
comment: "Max sign change - number of yes-no switches, max play : max number of plays"
positive: "maxSignChange", 5
positive: "maxPlay", 100
clicked = endPause: "OK", 1
if noiseTest
showStimuli=1
doStaricase=0
endif
soundID=Read from file: soundFilename$
# Change this to the target label for your unmodified word
keySoundName$ = selected$()
selectObject: keySoundName$
if noiseTest
Create Sound from formula: "noise", 1, 0, 1, 44100, "randomGauss(0,0.1)"
keySoundName$ ="Sound noise"
endif
Scale intensity: 70
# Show original signal and adjust spectrogram settings
View & Edit
editor: keySoundName$
Formant settings: 5500, 5, 0.025, 30, 1
Advanced formant settings: "Burg", 100000
endeditor
# Info
for i from 1 to nEmphasisSteps
k8va=i-1
selectObject: keySoundName$
# selectObject: "Sound YanniLauralReddit_monoScaled"
tId[i]= Filter (formula): "if x<50 then self else self*10^(k8va*log2(min(x,cutoff2)/cutoff1)/20) fi; rectangular band filter"
tName$="dBPerOct_"+string$(k8va)
Rename: tName$
choiceName$[i] = tName$
Scale intensity: 70
# View & Edit
# Play
# sleep: 1
endfor
if showStimuli
done=0
whichAtten=6
while done==0
beginPause: "Show which"
optionMenu: "WhichAtten", whichAtten
for i from 1 to nEmphasisSteps
option: choiceName$[i]
endfor
clicked = endPause: "OK",1
selectObject(tId[whichAtten])
Play
View & Edit
if noiseTest
@checkSpectrum()
selectObject(tId[whichAtten])
endif
beginPause: "More"
clickMore= endPause("Yes", "N0", 1)
if clickMore==2
done=1
endif
# Remove
endwhile
endif
if doStaircase
nResp=0
@staircase()
endif
procedure staircase()
#TempDemo
# You could change startLab$ here to show the "alternative" lavbel for the high dB/oct preemphasis
if startLow
startNum=1
yesInc=1.0
startLab$=lowTargetLabel$
else
startNum=nEmphasisSteps
startLab$=highTargetLabel$
yesInc=-1.0
endif
# keySoundName$ ="Sound laurelVocabularyScaled"
demo Black
demo Times
demo 24
demo Select inner viewport: 0, 100, 0, 100
demo Axes: 0, 100, 0, 100
demo Paint rectangle: "white", 0, 100, 0, 100
demo Text: 50, "centre", 80, "half", "Still hear " + startLab$ + " ?"
demo Text: 50, "centre", 50, "half", "Y | N"
signLast=0
this=startNum
selectObject: tId[this]
Play
waitTime= 0.75
sleep: waitTime
signChanges=0
maxPlay=100
iplay=1
noInc= -yesInc
incThis=yesInc
incLast=incThis
while demoWaitForInput()
if demoX()<50
# Listener says yes -- keep original increment direction
incThis = yesInc
# printline YES:, 'incThis', 'incLast'
resp[iplay] = 1
stimNum[iplay]=this
else
# Listner says no go backwards
resp[iplay] = 0
stimNum[iplay]=this
# pause incThis before NO assign; 'incThis'
incThis = noInc
# pause incThis after NO no assign: 'incThis'
# printline NO: incThis post, incLast, yesInc, 'incThis', 'incLast', 'yesInc', noInc: 'noInc'
if incThis <> noInc
pause Shouldnot happen
endif
endif
if incThis <> incLast
signChanges=signChanges+1
endif
incLast=incThis
if signChanges>maxSignChange
goto doneStaircase
endif
this=this+incThis
if this<1
this=1
endif
if this>nEmphasisSteps
this=nEmphasisSteps
endif
# printline inclast 'incLast', incThis 'incThis', this 'this', schg 'signChanges'
selectObject: tId[this]
Play
# sleep: waitTime
iplay=iplay+1
if iplay>maxPlay
goto doneStaircase
endif
endwhile
label doneStaircase
demo Erase all
appendInfoLine: "****************************************************"
appendInfoLine: "************ RESULTS OF THIS RUN *****************"
appendInfoLine: "***************************************************"
appendInfoLine: "Still hearing :", startLab$
appendInfoLine: "Stimulus number : ", "Response (1=y, 2=no)"
for i from 1 to iplay
appendInfoLine: stimNum[i], ":", resp[i]
endfor
endproc
procedure checkSpectrum()
# We have to write this to a temporary text file then
# read it back into a table
tLtasID=To Ltas: 100
ltasName$= selected$()
selectObject: ltasName$
nbins= Get number of bins
writeFileLine: "tmpLtas_dBOct.txt", "octAbove dB"
for ibin from 1 to nbins
f= Get frequency from bin number: ibin
if f>= cutoff1 and f<=cutoff2
db= Get value in bin: ibin
octAbove=log2(f/cutoff1)
appendFileLine: "tmpLtas_dBOct.txt", octAbove," ", db
endif
endfor
tTableID=Read Table from whitespace-separated file: "/Users/tnearey/Dropbox/YanniLauelMemeMay2018/tmpLtas_dBOct.txt"
tabName$=selected$()
printline 'tabName$'
View & Edit
tLinRegID=To linear regression
info$=Info
slope = extractNumber (info$, "Coefficient of factor octAbove: ")
appendInfoLine: "Slope " , slope , " dB/octave above ", cutoff1 , " Hz"
selectObject: tabName$
Erase all
Scatter plot (mark): "octAbove", 0, 0, "dB", 0, 0, 1, "yes", "+"
appendInfoLine: info$
selectObject(tLtasID,tTableID,tLinRegID)
Remove
endproc
@tnearey
Copy link
Author

tnearey commented May 19, 2018

This is the latest version of my praat script to produce Laurel to Yanni (though I hear Yari) shifts by preemphasizing the spectrum by k-dB per octave between 1000 and 10,000 Hz. See my comments in http://languagelog.ldc.upenn.edu/nll/?p=38274.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment