maeblythe

Export UST, dynamics, and Pitch for OpenUtau

Sep 28th, 2025
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. # select TextGrid with one interval tier with phonemes
  2. # and corresponding Pitch object
  3. # and corresponding intensity object
  4. # run this script
  5. # a file "praat.ust" will be created where this script is
  6. # stolen from Hataori-P
  7.  
  8. grid = selected: "TextGrid", 1
  9. pitch = selected: "Pitch", 1
  10. intensity = selected: "Intensity", 1
  11.  
  12. selectObject: grid
  13.  
  14. gNumTiers = Get number of tiers
  15. if gNumTiers <> 1
  16. exitScript: "TextGrid doesn't have only 1 tier"
  17. endif
  18.  
  19. gIsInterval = Is interval tier: 1
  20. if not gIsInterval
  21. exitScript: "TextGrid's tier is not Interval Tier"
  22. endif
  23.  
  24. gNumInts = Get number of intervals: 1
  25.  
  26.  
  27. deleteFile: "intend.txt"
  28. deleteFile: "praat.ust"
  29. deleteFile: "pitb.txt"
  30. appendFileLine: "praat.ust", "[#VERSION]"
  31. appendFileLine: "praat.ust", "UST Version1.2"
  32. appendFileLine: "praat.ust", "[#SETTING]"
  33. appendFileLine: "praat.ust", "Tempo=360.00"
  34. appendFileLine: "praat.ust", "Tracks=1"
  35. appendFileLine: "praat.ust", "ProjectName=Praat"
  36. appendFileLine: "praat.ust", "VoiceDir="
  37. appendFileLine: "praat.ust", "OutFile="
  38. appendFileLine: "praat.ust", "CacheDir=empty.cache"
  39. appendFileLine: "praat.ust", "Tool1=wavtool.exe"
  40. appendFileLine: "praat.ust", "Tool2=fresamp14.exe"
  41. appendFileLine: "praat.ust", "Mode2=True"
  42.  
  43. prevLbl$ = "-"
  44.  
  45. for .i to gNumInts
  46. selectObject: grid
  47. ts = Get start time of interval: 1, .i
  48. te = Get end time of interval: 1, .i
  49. lbl$ = Get label of interval: 1, .i
  50.  
  51. if lbl$ = ""
  52. lbl$ = "R"
  53. prevLbl$ = "-"
  54. endif
  55.  
  56. if lbl$ = "_"
  57. lbl$ = "R"
  58. prevLbl$ = "-"
  59. endif
  60.  
  61. if lbl$ = "R"
  62. prevLbl$ = "-"
  63. endif
  64.  
  65.  
  66. len = te - ts
  67. qlen = round(len * 960) * 3
  68.  
  69.  
  70. if lbl$ <> "R"
  71. selectObject: pitch
  72. semi_in_semitones = Get quantile: ts, te, 0.5, "semitones re 440 Hz"
  73. semi = round(semi_in_semitones) + 69 ; Convert to MIDI note
  74. else
  75. semi = 60 ; Default to MIDI note C4 for rests
  76. semi_in_semitones = (semi - 69) ; Convert MIDI note to semitones relative to 440 Hz
  77. endif
  78.  
  79. selectObject: pitch
  80. tsTick = round(ts * 960 * 3)
  81. tsTickT = round(te * 960 * 3)
  82. tsTickI = ts
  83.  
  84. scale_factor = 1 ; Adjust scale as needed
  85.  
  86.  
  87. while tsTickI < te
  88. pitb = Get quantile: tsTickI, tsTickI + 0.01, 0.5, "semitones re 440 Hz"
  89. if pitb = undefined
  90. pitb = semi_in_semitones ; Use the base pitch when undefined
  91. endif
  92.  
  93. ; Calculate pitch deviation
  94. adjusted_pitb = round(((pitb - semi_in_semitones) * scale_factor * 10) * 10)
  95.  
  96. appendFileLine: "pitb.txt", round((tsTickI) * 960 * 3), " ", adjusted_pitb
  97. tsTickI = tsTickI + 0.01
  98. endwhile
  99.  
  100. ; Later UST-related logic
  101. ; Here, you can safely use `semi` to determine the note since it retains the MIDI note value.
  102.  
  103.  
  104.  
  105.  
  106. if lbl$ <> "_"
  107. selectObject: intensity
  108. intens = Get quantile: ts, te, 0.50
  109. intens = round(intens)
  110. tsTick = round(ts * 960 * 3)
  111. tsTickT = round(te * 960 * 3)
  112. tsTickI = ts
  113. intens2 = 0
  114.  
  115. while tsTickI < te
  116.  
  117. intens2 = Get quantile: tsTickI, tsTickI + 0.01, 0.50
  118. if intens2 = undefined
  119. intens2 = 0
  120. endif
  121. appendFileLine: "intend.txt", round((tsTickI + 0.01) * 960 * 3), " ", round((intens2 * 4) - 280)
  122. tsTickI = tsTickI + 0.01
  123.  
  124.  
  125. endwhile
  126.  
  127.  
  128.  
  129.  
  130.  
  131. else
  132. intens = 60
  133. endif
  134.  
  135.  
  136.  
  137. appendFileLine: "praat.ust", "[#", .i, "]"
  138. appendFileLine: "praat.ust", "Length=", qlen
  139. appendFileLine: "praat.ust", "Lyric=", lbl$
  140. if semi > 0
  141. appendFileLine: "praat.ust", "NoteNum=", semi
  142. else
  143. appendFileLine: "praat.ust", "NoteNum=60"
  144. endif
  145. appendFileLine: "praat.ust", "PreUtterance="
  146. appendFileLine: "praat.ust", "Intensity=", intens
  147. appendFileLine: "praat.ust", "Modulation=0"
  148.  
  149. if lbl$ <> "R"
  150. prevLbl$ = lbl$
  151. else
  152. prevLbl$ = "-"
  153. endif
  154.  
  155. endfor
  156.  
  157. appendFileLine: "praat.ust", "[#TRACKEND]"
  158.  
  159. plusObject: pitch
  160.  
  161. writeInfoLine: "File Praat.ust created"
Advertisement
Add Comment
Please, Sign In to add comment