#!/usr/bin/env python3
"""
检查音频文件格式
"""
import os
import subprocess

cn_dir = "shitu_audio_segments"
tts_dir = "shitu_tts"

print("检查中文音频格式:")
print("=" * 50)
for i in range(3):
    idx = f"{i:03d}"
    cn_file = os.path.join(cn_dir, f"audio_line_{idx}.wav")
    if os.path.exists(cn_file):
        cmd = ['ffprobe', '-v', 'error', '-show_entries', 'stream=codec_name,sample_rate,channels',
               '-of', 'default=noprint_wrappers=1', cn_file]
        result = subprocess.run(cmd, capture_output=True, text=True)
        print(f"  句{i}: {result.stdout.strip()}")

print("\n检查TTS音频格式:")
print("=" * 50)
for i in range(3):
    idx = f"{i:03d}"
    tts_file = os.path.join(tts_dir, f"tts_line_{idx}.wav")
    if os.path.exists(tts_file):
        cmd = ['ffprobe', '-v', 'error', '-show_entries', 'stream=codec_name,sample_rate,channels',
               '-of', 'default=noprint_wrappers=1', tts_file]
        result = subprocess.run(cmd, capture_output=True, text=True)
        print(f"  句{i}: {result.stdout.strip()}")

print("\n检查TTS音频时长:")
print("=" * 50)
for i in range(10):
    idx = f"{i:03d}"
    tts_file = os.path.join(tts_dir, f"tts_line_{idx}.wav")
    if os.path.exists(tts_file):
        cmd = ['ffprobe', '-v', 'error', '-show_entries', 'format=duration',
               '-of', 'default=noprint_wrappers=1:nokey=1', tts_file]
        result = subprocess.run(cmd, capture_output=True, text=True)
        duration = float(result.stdout.strip()) if result.returncode == 0 else 0
        print(f"  句{i}: {duration:.2f}s")
