Spaces:
Sleeping
Sleeping
Commit
·
37f38b2
1
Parent(s):
6909f3d
feat: add coop in header
Browse files
app.py
CHANGED
@@ -1,24 +1,27 @@
|
|
1 |
import json
|
2 |
|
3 |
import gradio as gr
|
4 |
-
from omegaconf import OmegaConf
|
5 |
from huggingface_hub import snapshot_download
|
6 |
-
from
|
|
|
|
|
7 |
|
8 |
def load_vosk(model_id: str):
|
9 |
model_dir = snapshot_download(model_id)
|
10 |
return Model(model_path=model_dir)
|
11 |
|
|
|
12 |
OmegaConf.register_new_resolver("load_vosk", load_vosk)
|
13 |
|
14 |
models_config = OmegaConf.to_object(OmegaConf.load("configs/models.yaml"))
|
15 |
|
|
|
16 |
def automatic_speech_recognition(model_id: str, dialect_id: str, audio_data: str):
|
17 |
if isinstance(models_config[model_id]["model"], dict):
|
18 |
model = models_config[model_id]["model"][dialect_id]
|
19 |
-
else:
|
20 |
model = models_config[model_id]["model"]
|
21 |
-
|
22 |
sample_rate, audio_array = audio_data
|
23 |
if audio_array.ndim == 2:
|
24 |
audio_array = audio_array[:, 0]
|
@@ -30,14 +33,14 @@ def automatic_speech_recognition(model_id: str, dialect_id: str, audio_data: str
|
|
30 |
rec.SetWords(True)
|
31 |
|
32 |
results = []
|
33 |
-
|
34 |
for start in range(0, len(audio_bytes), 4000):
|
35 |
end = min(start + 4000, len(audio_bytes))
|
36 |
data = audio_bytes[start:end]
|
37 |
if rec.AcceptWaveform(data):
|
38 |
raw_result = json.loads(rec.Result())
|
39 |
results.append(raw_result)
|
40 |
-
|
41 |
final_result = json.loads(rec.FinalResult())
|
42 |
results.append(final_result)
|
43 |
|
@@ -48,7 +51,6 @@ def automatic_speech_recognition(model_id: str, dialect_id: str, audio_data: str
|
|
48 |
if len(result["text"]) > 0:
|
49 |
filtered_lines.append(result["text"])
|
50 |
|
51 |
-
|
52 |
return ",".join(filtered_lines) + "。"
|
53 |
|
54 |
|
@@ -113,6 +115,8 @@ with demo:
|
|
113 |
### 研發
|
114 |
- **[李鴻欣 Hung-Shin Lee](mailto:[email protected])([聯和科創](https://www.104.com.tw/company/1a2x6bmu75))**
|
115 |
- **[陳力瑋 Li-Wei Chen](mailto:[email protected])([聯和科創](https://www.104.com.tw/company/1a2x6bmu75))**
|
|
|
|
|
116 |
"""
|
117 |
)
|
118 |
gr.Interface(
|
|
|
1 |
import json
|
2 |
|
3 |
import gradio as gr
|
|
|
4 |
from huggingface_hub import snapshot_download
|
5 |
+
from omegaconf import OmegaConf
|
6 |
+
from vosk import KaldiRecognizer, Model
|
7 |
+
|
8 |
|
9 |
def load_vosk(model_id: str):
|
10 |
model_dir = snapshot_download(model_id)
|
11 |
return Model(model_path=model_dir)
|
12 |
|
13 |
+
|
14 |
OmegaConf.register_new_resolver("load_vosk", load_vosk)
|
15 |
|
16 |
models_config = OmegaConf.to_object(OmegaConf.load("configs/models.yaml"))
|
17 |
|
18 |
+
|
19 |
def automatic_speech_recognition(model_id: str, dialect_id: str, audio_data: str):
|
20 |
if isinstance(models_config[model_id]["model"], dict):
|
21 |
model = models_config[model_id]["model"][dialect_id]
|
22 |
+
else:
|
23 |
model = models_config[model_id]["model"]
|
24 |
+
|
25 |
sample_rate, audio_array = audio_data
|
26 |
if audio_array.ndim == 2:
|
27 |
audio_array = audio_array[:, 0]
|
|
|
33 |
rec.SetWords(True)
|
34 |
|
35 |
results = []
|
36 |
+
|
37 |
for start in range(0, len(audio_bytes), 4000):
|
38 |
end = min(start + 4000, len(audio_bytes))
|
39 |
data = audio_bytes[start:end]
|
40 |
if rec.AcceptWaveform(data):
|
41 |
raw_result = json.loads(rec.Result())
|
42 |
results.append(raw_result)
|
43 |
+
|
44 |
final_result = json.loads(rec.FinalResult())
|
45 |
results.append(final_result)
|
46 |
|
|
|
51 |
if len(result["text"]) > 0:
|
52 |
filtered_lines.append(result["text"])
|
53 |
|
|
|
54 |
return ",".join(filtered_lines) + "。"
|
55 |
|
56 |
|
|
|
115 |
### 研發
|
116 |
- **[李鴻欣 Hung-Shin Lee](mailto:[email protected])([聯和科創](https://www.104.com.tw/company/1a2x6bmu75))**
|
117 |
- **[陳力瑋 Li-Wei Chen](mailto:[email protected])([聯和科創](https://www.104.com.tw/company/1a2x6bmu75))**
|
118 |
+
### 合作單位
|
119 |
+
- **[國立聯合大學智慧客家實驗室](https://www.gohakka.org)**
|
120 |
"""
|
121 |
)
|
122 |
gr.Interface(
|