Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # select TextGrid with one interval tier with phonemes
- # and corresponding Pitch object
- # and corresponding intensity object
- # run this script
- # a file "praat.ust" will be created where this script is
- # stolen from Hataori-P
- grid = selected: "TextGrid", 1
- pitch = selected: "Pitch", 1
- intensity = selected: "Intensity", 1
- selectObject: grid
- gNumTiers = Get number of tiers
- if gNumTiers <> 1
- exitScript: "TextGrid doesn't have only 1 tier"
- endif
- gIsInterval = Is interval tier: 1
- if not gIsInterval
- exitScript: "TextGrid's tier is not Interval Tier"
- endif
- gNumInts = Get number of intervals: 1
- deleteFile: "intend.txt"
- deleteFile: "praat.ust"
- deleteFile: "pitb.txt"
- appendFileLine: "praat.ust", "[#VERSION]"
- appendFileLine: "praat.ust", "UST Version1.2"
- appendFileLine: "praat.ust", "[#SETTING]"
- appendFileLine: "praat.ust", "Tempo=360.00"
- appendFileLine: "praat.ust", "Tracks=1"
- appendFileLine: "praat.ust", "ProjectName=Praat"
- appendFileLine: "praat.ust", "VoiceDir="
- appendFileLine: "praat.ust", "OutFile="
- appendFileLine: "praat.ust", "CacheDir=empty.cache"
- appendFileLine: "praat.ust", "Tool1=wavtool.exe"
- appendFileLine: "praat.ust", "Tool2=fresamp14.exe"
- appendFileLine: "praat.ust", "Mode2=True"
- prevLbl$ = "-"
- for .i to gNumInts
- selectObject: grid
- ts = Get start time of interval: 1, .i
- te = Get end time of interval: 1, .i
- lbl$ = Get label of interval: 1, .i
- if lbl$ = ""
- lbl$ = "R"
- prevLbl$ = "-"
- endif
- if lbl$ = "_"
- lbl$ = "R"
- prevLbl$ = "-"
- endif
- if lbl$ = "R"
- prevLbl$ = "-"
- endif
- len = te - ts
- qlen = round(len * 960) * 3
- if lbl$ <> "R"
- selectObject: pitch
- semi_in_semitones = Get quantile: ts, te, 0.5, "semitones re 440 Hz"
- semi = round(semi_in_semitones) + 69 ; Convert to MIDI note
- else
- semi = 60 ; Default to MIDI note C4 for rests
- semi_in_semitones = (semi - 69) ; Convert MIDI note to semitones relative to 440 Hz
- endif
- selectObject: pitch
- tsTick = round(ts * 960 * 3)
- tsTickT = round(te * 960 * 3)
- tsTickI = ts
- scale_factor = 1 ; Adjust scale as needed
- while tsTickI < te
- pitb = Get quantile: tsTickI, tsTickI + 0.01, 0.5, "semitones re 440 Hz"
- if pitb = undefined
- pitb = semi_in_semitones ; Use the base pitch when undefined
- endif
- ; Calculate pitch deviation
- adjusted_pitb = round(((pitb - semi_in_semitones) * scale_factor * 10) * 10)
- appendFileLine: "pitb.txt", round((tsTickI) * 960 * 3), " ", adjusted_pitb
- tsTickI = tsTickI + 0.01
- endwhile
- ; Later UST-related logic
- ; Here, you can safely use `semi` to determine the note since it retains the MIDI note value.
- if lbl$ <> "_"
- selectObject: intensity
- intens = Get quantile: ts, te, 0.50
- intens = round(intens)
- tsTick = round(ts * 960 * 3)
- tsTickT = round(te * 960 * 3)
- tsTickI = ts
- intens2 = 0
- while tsTickI < te
- intens2 = Get quantile: tsTickI, tsTickI + 0.01, 0.50
- if intens2 = undefined
- intens2 = 0
- endif
- appendFileLine: "intend.txt", round((tsTickI + 0.01) * 960 * 3), " ", round((intens2 * 4) - 280)
- tsTickI = tsTickI + 0.01
- endwhile
- else
- intens = 60
- endif
- appendFileLine: "praat.ust", "[#", .i, "]"
- appendFileLine: "praat.ust", "Length=", qlen
- appendFileLine: "praat.ust", "Lyric=", lbl$
- if semi > 0
- appendFileLine: "praat.ust", "NoteNum=", semi
- else
- appendFileLine: "praat.ust", "NoteNum=60"
- endif
- appendFileLine: "praat.ust", "PreUtterance="
- appendFileLine: "praat.ust", "Intensity=", intens
- appendFileLine: "praat.ust", "Modulation=0"
- if lbl$ <> "R"
- prevLbl$ = lbl$
- else
- prevLbl$ = "-"
- endif
- endfor
- appendFileLine: "praat.ust", "[#TRACKEND]"
- plusObject: pitch
- writeInfoLine: "File Praat.ust created"
Advertisement
Add Comment
Please, Sign In to add comment