File size: 1,888 Bytes
65b8210
194dd0f
 
40c2114
65b8210
194dd0f
 
 
40c2114
 
194dd0f
40c2114
 
194dd0f
 
 
 
 
 
40c2114
194dd0f
 
 
 
 
 
cf36334
194dd0f
40c2114
 
 
 
 
194dd0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40c2114
194dd0f
40c2114
194dd0f
 
 
65b8210
194dd0f
 
 
 
65b8210
194dd0f
 
 
40c2114
194dd0f
 
 
 
65b8210
 
194dd0f
b185d20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import gradio as gr
from fastapi import FastAPI
from api.routes import router as voice_router
import numpy as np

# -----------------------------
# FastAPI core app
# -----------------------------
app = FastAPI(
    title="Auralis Vocal Fatigue Scoring API",
    version="1.0"
)

# Register API routes
app.include_router(
    voice_router,
    prefix="/api/v1/voice",
    tags=["Vocal Fatigue Scoring"]
)

@app.get("/")
def root():
    return {
        "name": "Auralis Vocal Fatigue Scoring API",
        "status": "running",
        "api": "/api/v1/voice/score",
        "ui": "/"
    }

@app.get("/health")
def health():
    return {"status": "ok"}

# -----------------------------
# Gradio interface
# -----------------------------
from audio.preprocessing import load_audio, extract_features
from model.ecapa import ECAPAENCODER
from model.scorer import fatigue_score_0_to_100
from core.config import LOW_PERCENTILE, HIGH_PERCENTILE, FATIGUE_AXIS, REF_C_H

# Load once (IMPORTANT)
encoder = ECAPAENCODER()
C_h = np.load(REF_C_H)
fatigue_axis = np.load(FATIGUE_AXIS)
low = float(np.load(LOW_PERCENTILE)["arr_0"])
high = float(np.load(HIGH_PERCENTILE)["arr_0"])

def gradio_score(audio_path: str):
    """
    Direct pipeline call (NO HTTP, NO API call)
    """
    wav = load_audio(audio_path)
    _ = extract_features(wav)
    wav = wav.squeeze()

    emb = encoder.encode(wav)
    score = float(
        fatigue_score_0_to_100(emb, C_h, fatigue_axis, low, high)
    )

    return score

gradio_app = gr.Interface(
    fn=gradio_score,
    inputs=gr.Audio(type="filepath", label="Upload speech audio"),
    outputs=gr.Number(label="Vocal Fatigue Score (0โ€“100)"),
    title="Auralis โ€“ Vocal Fatigue Scoring",
    description="Upload speech audio to obtain an objective vocal fatigue score."
)

# ๐Ÿ”‘ Mount Gradio onto FastAPI
app = gr.mount_gradio_app(app, gradio_app, path="/")