Mentosyevsky commited on
Commit
aa4e6cf
·
verified ·
1 Parent(s): 5041430

Update audio.py

Browse files
Files changed (1) hide show
  1. audio.py +9 -5
audio.py CHANGED
@@ -1,5 +1,5 @@
1
  # audio.py
2
- import whisper
3
  import os
4
  import tempfile
5
  from text import analyze_text # ✅ 导入文字分析模块
@@ -14,10 +14,14 @@ def analyze_audio(file_path, lang=None):
14
  tmp.write(f.read())
15
 
16
  try:
17
- # 1️⃣ Whisper 转录
18
- model = whisper.load_model("base")
19
- result = model.transcribe(tmp_path)
20
- transcribed_text = result.get("text", "").strip()
 
 
 
 
21
 
22
  if transcribed_text:
23
  output += f"🔊 Whisper 语音识别完成:\n{transcribed_text}\n\n"
 
1
  # audio.py
2
+ from faster_whisper import WhisperModel
3
  import os
4
  import tempfile
5
  from text import analyze_text # ✅ 导入文字分析模块
 
14
  tmp.write(f.read())
15
 
16
  try:
17
+ # 使用 faster-whisper 的 tiny 模型,适合 CPU 环境
18
+ model = WhisperModel("tiny", device="cpu", compute_type="int8")
19
+
20
+ # 自动语言识别 & 转录
21
+ segments, info = model.transcribe(tmp_path, beam_size=5)
22
+
23
+ # 拼接所有转录文字
24
+ transcribed_text = "".join([seg.text for seg in segments]).strip()
25
 
26
  if transcribed_text:
27
  output += f"🔊 Whisper 语音识别完成:\n{transcribed_text}\n\n"