[结束提示音优化]:完成Codex通知音资产内置,包含音频提取、配置默认值和回归测试

This commit is contained in:
mkbk
2026-06-18 14:10:34 +08:00
parent 80549fb312
commit d83f5a19cb
14 changed files with 102 additions and 8 deletions
+49 -1
View File
@@ -170,7 +170,55 @@ def make_prompt_chime(
channels,
0,
duration_ms,
{"chime": "end", "text": "end_chime"},
{"chime": "end", "text": "end_chime", "source": "synthetic"},
)
def make_end_chime(
*,
file_path: str | Path | None = None,
frequency_hz: int = 880,
duration_ms: int = 140,
sample_rate: int = 16000,
channels: int = 1,
) -> AudioSegment:
if file_path is not None:
segment = _load_chime_file(Path(file_path))
if segment is not None:
return segment
return make_prompt_chime(
frequency_hz=frequency_hz,
duration_ms=duration_ms,
sample_rate=sample_rate,
channels=channels,
)
def _load_chime_file(path: Path) -> AudioSegment | None:
if not path.is_file():
return None
data = path.read_bytes()
if not data:
return None
suffix = path.suffix.lower().lstrip(".") or "wav"
sample_rate = 16000
channels = 1
duration_ms = 120
if suffix == "wav":
try:
with wave.open(str(path), "rb") as handle:
sample_rate = handle.getframerate()
channels = handle.getnchannels()
duration_ms = int(handle.getnframes() / max(1, sample_rate) * 1000)
except wave.Error:
pass
return AudioSegment(
data,
sample_rate,
channels,
0,
max(20, duration_ms),
{"chime": "end", "text": "end_chime", "format": suffix, "path": str(path), "source": "file"},
)