You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Praat脚本开发:如何提取每个音节的基频最大值?

Fixing Your Praat Script for Extracting Maximum Pitch per Syllable

Let's walk through the issues in your script and fix it step by step.

First, the core problem with your original code: when you run Get maximum, Praat needs to explicitly target the Pitch object—your initial selection includes both the TextGrid and Pitch, which can lead to Praat running commands on the wrong item by default. We’ll also add safeguards to avoid crashes if a syllable interval has no detected pitch data.

Here’s the corrected script with clear explanations:

writeInfoLine: ""

# Explicitly select the TextGrid first to access syllable intervals
selectObject: "TextGrid example"
# Syllable tier is set to 1
number = Get number of intervals: 1

# Select the Pitch object once (we’ll switch back to it in the loop)
selectObject: "Pitch example"

for i from 1 to number
    # Switch to TextGrid to fetch interval details
    selectObject: "TextGrid example"
    name$ = Get label of interval: 1, i
    start_time = Get start time of interval: 1, i
    end_time = Get end time of interval: 1, i
    
    # Switch back to Pitch object to calculate max pitch
    selectObject: "Pitch example"
    max_pitch = Get maximum: start_time, end_time, "Hertz", "Parabolic"
    
    # Handle cases where no pitch was detected (returns 'undefined')
    if max_pitch == undefined
        appendInfoLine: name$, " ", "No pitch data"
    else
        appendInfoLine: name$, " ", max_pitch
    endif
endfor

Key Fixes & Improvements:

  • Explicit object targeting: We switch between the TextGrid and Pitch object intentionally to eliminate ambiguity—Praat always knows which object to run commands on.
  • Error handling for missing pitch data: The if check catches cases where no pitch is detected in an interval, preventing the script from crashing and making your output more informative.
  • Cleaner readability: Separating object selections makes the script easier to debug and adjust later, especially if you modify tier numbers or object names.

A quick sanity check: ensure your TextGrid and Pitch object names exactly match what’s in your Praat object list (names are case-sensitive!). If you’re working with imported files instead of named objects, you can use selectObject: 1/selectObject: 2 based on their position in the object window instead of hardcoding names.

内容的提问来源于stack exchange,提问作者dgr379

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:31:03