#!/usr/bin/env python3 import warnings warnings.filterwarnings('ignore') from funasr import AutoModel import os import subprocess print("🔄 加载 FunASR 模型...") print(" 首次会自动下载模型(约100MB)到 ~/.cache/modelscope") print(" 请等待...\n") model = AutoModel( model="paraformer-zh", vad_model="fsmn-vad", punc_model="ct-punc", ) print("\n✅ FunASR 模型加载完成!") # 测试文件 uploads_dir = 'uploads' if os.path.exists(uploads_dir): files = [f for f in os.listdir(uploads_dir) if f.endswith(('.webm', '.wav', '.mp3'))] if files: test_file = os.path.join(uploads_dir, files[0]) print(f"\n🎵 测试文件: {test_file}") # 转换为 wav wav_file = test_file + '.wav' subprocess.run(['ffmpeg', '-y', '-i', test_file, '-ar', '16000', '-ac', '1', wav_file], capture_output=True) print("📝 开始识别...") res = model.generate(input=wav_file, batch_size_s=300) text = res[0]["text"] print(f"\n✅ 识别结果:") print(f" {text}") if os.path.exists(wav_file): os.remove(wav_file) else: print("\n⚠️ 没有测试音频") else: print("\n⚠️ uploads 目录不存在")