AI 工具

Auphonic 处理前:校验 Preset 与响度参数

创建 Production 前,先校验标题、preset、响度目标与 tags。这篇 presetcheck.py 不调用计费接口,只挡住明显坏配置。

BINBHO · 图文教程

创建 Production 前,先校验标题、preset、响度目标与 tags。这篇 preset_check.py 不调用计费接口,只挡住明显坏配置。

先看清成品

  • sample_ok → OK;sample_bad → INVALID(响度越界、tags 类型、章节缺字段)。
  • 3 项 pytest 通过。

合规提醒:只处理你有权处理的录音;采访/播客需取得嘉宾与版权授权。Auphonic 按处理时长计费,免费额度与套餐以官网为准,本文不编造分钟数或价格。API Token 等同账号权限,勿提交公开仓库。

运行说明:无正式 Auphonic Token。A/C 为本地元数据与章节校验;B 用 mock 演示 create→upload→start。对官方 auphonic.com/api 无效 Token 实测 HTTP 403(Token doesn't exist)。2026-10-23(Asia/Shanghai)pytest 通过。

做完之后你会得到什么?

成果 说明
preset_check.py 配置预检
样例 JSON ok/bad
test_101a.py 测试

需要准备哪些环境?

项目 说明
Python 3.10+

关键事实

事实 来源
Production 可绑定 preset,并附 metadata(title/artist/tags 等) 官方 API Docs
响度目标常用播客约 -16 LUFS 等;本教程软范围 [-30,-6] 实践 / 行业常见值
本脚本不代替 Auphonic 算法参数正确性 重要

文件结构

101-auphonic-A-src/
├── preset_check.py
├── sample_ok.json
├── sample_bad.json
└── test_101a.py

第 1 步:预检脚本

#!/usr/bin/env python3
"""Validate Auphonic-oriented podcast preset / production metadata before API create."""
from __future__ import annotations

import argparse
import json
from pathlib import Path

# Common podcast loudness targets (LUFS). Auphonic applies algorithms; we only validate intent.
KNOWN_TARGETS = {
    "podcast": -16,
    "youtube": -14,
    "broadcast_ebu": -23,
    "amazon_music": -14,
}


def validate(cfg: dict) -> list[str]:
    errs = []
    title = (cfg.get("metadata") or {}).get("title") or cfg.get("title")
    if not title or not str(title).strip():
        errs.append("metadata.title 必填")
    preset = cfg.get("preset")
    if not preset:
        errs.append("preset(名称或 UUID)建议填写,便于复用算法参数")
    target = cfg.get("loudnesstarget") or cfg.get("loudness_target")
    if target is not None:
        try:
            v = float(target)
            if not (-30 <= v <= -6):
                errs.append(f"loudness target {v} 超出常见范围 [-30,-6] LUFS")
        except (TypeError, ValueError):
            errs.append("loudness target 须为数字(LUFS)")
    profile = (cfg.get("profile") or "").lower()
    if profile and profile not in KNOWN_TARGETS:
        errs.append(f"未知 profile={profile};已知: {', '.join(KNOWN_TARGETS)}")
    tags = (cfg.get("metadata") or {}).get("tags")
    if tags is not None and not isinstance(tags, list):
        errs.append("metadata.tags 应为数组")
    # Chapters light check if present
    for i, ch in enumerate(cfg.get("chapters") or []):
        if "start" not in ch or "title" not in ch:
            errs.append(f"chapters[{i}] 需要 start 与 title")
    return errs


def main(argv=None) -> int:
    ap = argparse.ArgumentParser(description=__doc__)
    ap.add_argument("config_json")
    args = ap.parse_args(argv)
    cfg = json.loads(Path(args.config_json).read_text(encoding="utf-8"))
    errs = validate(cfg)
    if errs:
        print("INVALID")
        for e in errs:
            print("-", e)
        return 1
    meta = cfg.get("metadata") or {}
    print("OK")
    print(json.dumps({"title": meta.get("title") or cfg.get("title"), "preset": cfg.get("preset")}, ensure_ascii=False))
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

第 2 步:测试

from pathlib import Path
import json
import subprocess
import sys
from preset_check import validate

HERE = Path(__file__).resolve().parent

def test_ok():
    assert validate(json.loads((HERE/"sample_ok.json").read_text())) == []

def test_bad():
    assert validate(json.loads((HERE/"sample_bad.json").read_text()))

def test_cli():
    r = subprocess.run([sys.executable, str(HERE/"preset_check.py"), str(HERE/"sample_ok.json")], capture_output=True, text=True)
    assert r.returncode == 0 and "OK" in r.stdout

第 3 步:运行

$ python preset_check.py sample_ok.json
OK
{"title": "第 12 期:远程团队沟通", "preset": "My Podcast Preset"}

$ python preset_check.py sample_bad.json
INVALID
- metadata.title 必填
- preset(名称或 UUID)建议填写,便于复用算法参数
- loudness target 5.0 超出常见范围 [-30,-6] LUFS
- metadata.tags 应为数组
- chapters[0] 需要 start 与 title

$ pytest -q
...                                                                      [100%]
3 passed in 0.03s

怎么检查结果?

  • OK 样例无错误行。
  • bad 样例至少指出 loudness / tags / chapters 之一。

调试示例

把 YouTube -14 写成 +14。 校验会拦正值与过亮目标。若你确有特殊母带需求,先在网页端试听再改脚本软范围。

常见问题

现象 原因 处理
preset 用名称还是 UUID 二者皆可 控制台复制最稳
没有 metadata title 仍建议有 便于输出文件命名
只做校验 不花处理分钟 先本地再 POST

模板规则

  • 勿上传无权录音。
  • Token 保密。
  • 响度目标按发行平台核对。

项目资源

用途 地址
API Docs(官方) https://auphonic.com/api-docs/index.html
API 索引(官方) https://auphonic.com/api-docs/
Auphonic 官网 https://auphonic.com/

配置干净,再消耗处理时长。