Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,46 +5,51 @@ import shutil
|
|
5 |
from funasr import AutoModel
|
6 |
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
7 |
|
|
|
|
|
|
|
|
|
|
|
8 |
app = FastAPI()
|
9 |
|
10 |
-
# Load mô hình SenseVoiceSmall
|
11 |
-
model_dir = "FunAudioLLM/SenseVoiceSmall"
|
12 |
-
|
13 |
-
|
14 |
-
model = AutoModel(
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
)
|
21 |
-
|
22 |
-
# Hàm tính RMS energy
|
23 |
-
def calculate_rms_energy(audio_path):
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
# Hàm phát hiện tiếng ồn
|
29 |
-
def detect_noise(audio_path):
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
# API nhận file âm thanh từ Flutter
|
43 |
-
@app.post("/detect-noise/")
|
44 |
-
async def detect_noise_api(file: UploadFile = File(...)):
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
5 |
from funasr import AutoModel
|
6 |
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
7 |
|
8 |
+
from funasr import list_models
|
9 |
+
|
10 |
+
print(list_models()) # Xem danh sách model hỗ trợ
|
11 |
+
|
12 |
+
|
13 |
app = FastAPI()
|
14 |
|
15 |
+
# # Load mô hình SenseVoiceSmall
|
16 |
+
# model_dir = "FunAudioLLM/SenseVoiceSmall"
|
17 |
+
|
18 |
+
|
19 |
+
# model = AutoModel(
|
20 |
+
# model=model_dir,
|
21 |
+
# vad_model="fsmn-vad",
|
22 |
+
# vad_kwargs={"max_single_segment_time": 30000},
|
23 |
+
# device="cuda:0",
|
24 |
+
# hub="hf",
|
25 |
+
# )
|
26 |
+
|
27 |
+
# # Hàm tính RMS energy
|
28 |
+
# def calculate_rms_energy(audio_path):
|
29 |
+
# y, sr = librosa.load(audio_path)
|
30 |
+
# rms = librosa.feature.rms(y=y)[0]
|
31 |
+
# return np.mean(rms)
|
32 |
+
|
33 |
+
# # Hàm phát hiện tiếng ồn
|
34 |
+
# def detect_noise(audio_path):
|
35 |
+
# rms_energy = calculate_rms_energy(audio_path)
|
36 |
+
# res = model.generate(input=audio_path, language="auto", audio_event_detection=True)
|
37 |
+
# audio_events = res[0].get("audio_event_detection", {})
|
38 |
+
|
39 |
+
# if rms_energy > 0.02:
|
40 |
+
# return "ồn ào"
|
41 |
+
# elif rms_energy > 0.01:
|
42 |
+
# for event_label, event_score in audio_events.items():
|
43 |
+
# if event_score > 0.7 and event_label in ["laughter", "applause", "crying", "coughing"]:
|
44 |
+
# return f"ồn ào ({event_label})"
|
45 |
+
# return "yên tĩnh"
|
46 |
+
|
47 |
+
# # API nhận file âm thanh từ Flutter
|
48 |
+
# @app.post("/detect-noise/")
|
49 |
+
# async def detect_noise_api(file: UploadFile = File(...)):
|
50 |
+
# file_path = f"temp/{file.filename}"
|
51 |
+
# with open(file_path, "wb") as buffer:
|
52 |
+
# shutil.copyfileobj(file.file, buffer)
|
53 |
+
|
54 |
+
# result = detect_noise(file_path)
|
55 |
+
# return {"noise_level": result}
|