Spaces:
Sleeping
Sleeping
Update audio.py
Browse files
audio.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# audio.py
|
| 2 |
-
import
|
| 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 |
-
#
|
| 18 |
-
model =
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"
|