2007-12-12

[Phonetics] Praat腳本:語調標記與繪圖

為了要幫葉老師的書畫一些語調圖,所以寫了一個Praat腳本來處理這些dirty work。這也是真正第一個自己寫的Praat腳本,值得慶賀一下(終於學會了 ^^y )。

腳本的功能說明:

  1. 標記語調
  2. 提取音高,手動修正野點(wild point),平滑
  3. 畫音波圖和語調曲拱
  4. 存檔(附檔名TextGrid、Pitch、wmf)

流程圖示
Praat腳本流程圖


######################################
# Annotate and draw intonation
#
# Author: Zhunbang Pbice Liao
# Praat Version: 4.6.34
# Last Update: 2007.10.23
######################################

form File Directory
  
comment Input file directory
  sentence directory c:\praat\
endform

# Create a string file that lists file names.

Create Strings as file list... list 'directory$'*.wav
numberOfFiles
= Get number of strings

# if !numberOfFiles
#
  Create Strings as file list... list'directory$'*.WAV
#
  numberOfFiles = Get number of strings
# endif

# Loop to read in files

for ifile to numberOfFiles
  
select Strings list
  
fileName$ = Get string... ifile
  
Read from file... 'directory$''fileName$'
  
name$ = fileName$ -".wav" -".WAV"

# Skip labeling if TextGrid files already exist

  if fileReadable (directory$+name$+".TextGrid")
    Read from file... 'directory$''name$'.TextGrid
  
else
# Do labeling
    select Sound 'name$'
    
To TextGrid... Romanization
    plus Sound 'name$'
    Edit
    pause Annotate the sound then click "continue"
    endeditor
  endif

# Skip extract pitch contour if Pitch file exit

  if fileReadable (directory$+name$+".Pitch")
    Read from file... 'directory$''name$'.Pitch
  else   

# Extract pitch contour

    select Sound 'name$'
    To Pitch... 0 50 300
    select Pitch 'name$'
    Edit
    select Sound 'name$'
    plus TextGrid 'name$'

# Edit

    pause Fix pitch points then click "continue"
    endeditor
    endeditor
    select Pitch 'name$'
    Smooth... 5
   endif

  

# Draw waveform

  Erase all
  Black
  14
  Helvetica
  select Sound 'name$'
  Select outer viewport... 0 7.5 0 1.5
  
Line width... 1
  Draw... 0 0 0 0 no Curve

# Draw intonation contour

  select Pitch 'name$'
  
plus TextGrid 'name$'
    
Line width... 3
  
Select outer viewport... 0 7.5 0.5 5.5
  Draw separately... 0 0 0 300 yes yes yes

  Line width... 3
  
Draw separately... 0 0 0 300 no no no
    
Line width... 3.5
  Select outer viewport... 0 7.5 0 5.5
  Axes... 0 7.5 0 5.5
  Draw rectangle... 0 7.5 0 5.5

  

# Save File

  Write to Windows metafile... 'directory$''name$'.wmf
  if not fileReadable (directory$+name$+".TextGrid")
    select TextGrid 'name$'
    Write to text file... 'directory$''name$'.TextGrid
  endif
  if not fileReadable (directory$+name$+".Pitch")
    select Pitch 'name$'
    Write to text file... 'directory$''name$'.Pitch
  endif

# Remove

  select Sound 'name$'
  plus TextGrid 'name$'
  plus Pitch 'name$'
  Remove
  
select Pitch 'name$'
  Remove  

endfor

select all

Remove

# End of script

[Phonetics] Praat 5.0 發佈

語音學研究軟體Praat發佈了5.0版!這實在是令人興奮的消息。究竟5.0版有什麼功能改進呢?主要的有:
  • 支援Unicode:5.0最大的改進就是全面支援Unicode了!早期Praat只支援ASCII,從4.6版開始,陸續支援Unicode。現在script、string、table、OT learning、檔案名稱......等都可以使用Uincode了。雖然目前中文字在TextGrid視窗還無法正常顯示,但存成文字檔不成問題(UTF-16編碼)。作者承諾未來在5.1版全面支援中文。
  • 加大Pitcure視窗:雖然預設值一樣都是4x6英吋,但新版的Pitcure視窗比較大,感覺像是放大比例,或是拉近距離。
  • 在Sound和TextGrid視窗,新增Draw指令(在File命令之下)。可以直接在Picture視窗畫出選取區域的圖形。
  • 改善羅吉斯回歸(logistic regression)
  • 改善優選論(optimality theory)學習
  • 改善複製圖片到剪貼簿
  • 可讀取FLAC檔案
因為Win 95 & 98不支援Unicode,所以Praat 5.0開始,也無法在Win 98以下的版本運行了。

【延伸閱讀】