From 9ac819269338a587c5cc23f63493c84d90a5a432 Mon Sep 17 00:00:00 2001 From: ymq Date: Mon, 10 Aug 2026 17:42:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=86=E9=A2=91=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A3=B0=E7=BA=B9=E6=8F=90=E5=8F=96=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20metadata=20=E6=B0=B8=E8=BF=9C=20pending?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 视频处理新增:ffmpeg 提取音频 → voiceprint/extract 声纹 API - meta_parts['video'] 成功时从 'pending' 改为 'done' - voiceprint 结果写入 meta_parts --- wwwroot/knowledge_bases_list/upload_file.dspy | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/wwwroot/knowledge_bases_list/upload_file.dspy b/wwwroot/knowledge_bases_list/upload_file.dspy index da29501..91c1add 100644 --- a/wwwroot/knowledge_bases_list/upload_file.dspy +++ b/wwwroot/knowledge_bases_list/upload_file.dspy @@ -121,9 +121,10 @@ async def ingest_doc(doc_id, kb_id, file_name, ext_l, real_path): meta_parts['voiceprint'] = voice_speakers except: pass - # --- VIDEO: frame extraction --- + # --- VIDEO: frame extraction + voiceprint --- if ext_l in video_exts: meta_parts['video'] = 'pending' + video_ok = False try: tmp_img = '/tmp/' + doc_id + '_frame.jpg' subprocess.run(['ffmpeg', '-y', '-i', real_path, '-vframes', '1', '-q:v', '2', tmp_img], @@ -166,8 +167,35 @@ async def ingest_doc(doc_id, kb_id, file_name, ext_l, real_path): except: pass os.remove(tmp_img) + video_ok = True except: pass + # --- Voiceprint: extract audio from video --- + if video_ok: + try: + tmp_wav = '/tmp/' + doc_id + '_audio.wav' + subprocess.run(['ffmpeg', '-y', '-i', real_path, '-vn', '-acodec', 'pcm_s16le', + '-ar', '16000', '-ac', '1', tmp_wav], + capture_output=True, timeout=60) + if os.path.exists(tmp_wav) and os.path.getsize(tmp_wav) > 1000: + with open(tmp_wav, 'rb') as fa: + audio_data = fa.read() + try: + client4 = StreamHttpClient() + resp4 = await client4.request('POST', + 'https://media.opencomputing.net:10443/voiceprint/extract/submit', + files={'file': (file_name.rsplit('.', 1)[0] + '.wav', audio_data)}) + vd = json.loads(resp4) + voice_speakers = vd.get('speakers', 1) if vd.get('status') == 'SUCCEEDED' else (1 if vd.get('embedding') else 0) + meta_parts['voiceprint'] = voice_speakers + except: pass + if os.path.exists(tmp_wav): + os.remove(tmp_wav) + except: pass + + if video_ok: + meta_parts['video'] = 'done' + # --- RAG INGEST for text --- if text and len(text.strip()) > 10: paragraphs = text.split('\n')