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

如何修改Praat脚本批量获取WAV文件的最大与最小基频

批量提取WAV文件基频的最大/最小值(Praat脚本修改方案)

问题描述

我有大量WAV文件,需要获取每个文件的最大和最小基频。尝试使用max = Get maximum语句但未成功,求修改以下Praat脚本实现需求。

原脚本

form Process files...
  sentence Path /path/to/your/files
endform

# Optional: make sure the path has a trailing slash
path$ = if right$(path$) = "/" then path$ else path$ + "/" fi

output = Create Table with column names: "output", 0,
  ... "file mean_pitch"

files = Create Strings as file list: "files", path$ + "*wav"
total_files = Get number of strings
for i to total_files
  selectObject: files
  filename$ = Get string: i
  sound = Read from file: path$ + filename$

  # Run whatever kind of analysis you want here
  # For example, get the mean pitch for each file

  pitch = To Pitch: 0, 75, 600
  mean = Get mean: 0, 0, "Hertz"

  selectObject: output
  Append row
  row = Get number of rows
  Set string value: row, "file", filename$
  Set numeric value: row, "mean_pitch", mean

  removeObject: sound, pitch
endfor

selectObject: output
Save as comma-separated file: path$ + "output.csv"

removeObject: files, output

修改后的完整脚本

form Process files...
  sentence Path /path/to/your/files
endform

# 确保路径末尾有斜杠
path$ = if right$(path$) = "/" then path$ else path$ + "/" fi

# 新增min_pitch和max_pitch列
output = Create Table with column names: "output", 0,
  ... "file mean_pitch min_pitch max_pitch"

files = Create Strings as file list: "files", path$ + "*wav"
total_files = Get number of strings
for i to total_files
  selectObject: files
  filename$ = Get string: i
  sound = Read from file: path$ + filename$

  # 生成Pitch对象
  pitch = To Pitch: 0, 75, 600
  # 获取均值、最小值、最大值(0,0表示覆盖整个音频时长)
  mean = Get mean: 0, 0, "Hertz"
  min_pitch = Get minimum: 0, 0, "Hertz"
  max_pitch = Get maximum: 0, 0, "Hertz"

  selectObject: output
  Append row
  row = Get number of rows
  Set string value: row, "file", filename$
  Set numeric value: row, "mean_pitch", mean
  # 写入最小、最大基频
  Set numeric value: row, "min_pitch", min_pitch
  Set numeric value: row, "max_pitch", max_pitch

  removeObject: sound, pitch
endfor

selectObject: output
Save as comma-separated file: path$ + "output_pitch_stats.csv"

removeObject: files, output

关键修改点说明

  • 表格列扩展:在创建输出表格时,新增min_pitch和max_pitch列,用于存储提取到的极值
  • 正确调用极值命令:Praat的Pitch对象Get maximum/Get minimum必须指定三个参数:起始时间、结束时间(0,0表示整个音频时长)、单位(这里用"Hertz"),之前的错误大概率是缺少参数导致的
  • 写入极值数据:在写入均值后,新增两行代码把最小、最大基频对应写入表格的列中
  • 输出文件名优化:把输出CSV文件名改为output_pitch_stats.csv,更直观反映内容

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 10:20:15