avec les defs
Browse files- DTW_api.py +27 -7
- static/assets/index-Bef3m2Pk.js +0 -0
- static/assets/index-CtkwHOHY.js +0 -0
- static/assets/index-DHYokP5o.css +1 -0
- static/assets/index-DjwIwxr1.js +0 -0
- static/index.html +3 -3
- wtcsay-defs.txt +0 -0
DTW_api.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
|
| 2 |
import re
|
|
|
|
| 3 |
import unicodedata as ud
|
| 4 |
from typing import Tuple
|
| 5 |
from io import BytesIO
|
|
@@ -159,8 +160,9 @@ def rank_by_dtw(query_seq: np.ndarray, corpus_df: pd.DataFrame, seq_col: str = "
|
|
| 159 |
for idy, cost in top:
|
| 160 |
r = corpus_df.loc[idy]
|
| 161 |
results.append({
|
| 162 |
-
'
|
| 163 |
-
'
|
|
|
|
| 164 |
'path': str(r.get('path')),
|
| 165 |
'speaker': str(r.get('speaker')),
|
| 166 |
'n_frames': int(r.get('n_frames')),
|
|
@@ -324,6 +326,22 @@ def transcribe_np(audio_np, sr=16000) -> str:
|
|
| 324 |
# ================== Main Function: ASR + Retrieval ==================
|
| 325 |
|
| 326 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
def main_asr(audio_np):
|
| 328 |
hyp_gdpi = transcribe_np(audio_np) # ASR output in gdpi
|
| 329 |
hyp_ggn = convert_gdpi_to_ggn(hyp_gdpi) # parsetc -> ggn
|
|
@@ -335,10 +353,11 @@ def main_asr(audio_np):
|
|
| 335 |
|
| 336 |
# print("\n====== Top-{} Retrieval (Levenshtein on GGN no-tone) ======".format(TOPK))
|
| 337 |
results = []
|
| 338 |
-
for
|
| 339 |
rank = int(row["rank"])
|
| 340 |
py_ref = row["Ref_pinyin_ggn_pengim"]
|
| 341 |
-
|
|
|
|
| 342 |
han = ""
|
| 343 |
if "chinese_simple" in topk_df.columns and pd.notna(row["chinese_simple"]):
|
| 344 |
han = row["chinese_simple"]
|
|
@@ -350,12 +369,13 @@ def main_asr(audio_np):
|
|
| 350 |
print(han)
|
| 351 |
# results.append({'han': han, 'pi': py_ref})
|
| 352 |
results.append({
|
| 353 |
-
'
|
| 354 |
-
'
|
|
|
|
| 355 |
# 'path': "path",
|
| 356 |
# 'speaker': "spkr",
|
| 357 |
# 'n_frames': 0,
|
| 358 |
-
'score':
|
| 359 |
})
|
| 360 |
return results
|
| 361 |
|
|
|
|
| 1 |
|
| 2 |
import re
|
| 3 |
+
from pathlib import Path
|
| 4 |
import unicodedata as ud
|
| 5 |
from typing import Tuple
|
| 6 |
from io import BytesIO
|
|
|
|
| 160 |
for idy, cost in top:
|
| 161 |
r = corpus_df.loc[idy]
|
| 162 |
results.append({
|
| 163 |
+
'sino': str(r.get('text')),
|
| 164 |
+
'pi': str(r.get('pinyin')),
|
| 165 |
+
'def': "def à venir",
|
| 166 |
'path': str(r.get('path')),
|
| 167 |
'speaker': str(r.get('speaker')),
|
| 168 |
'n_frames': int(r.get('n_frames')),
|
|
|
|
| 326 |
# ================== Main Function: ASR + Retrieval ==================
|
| 327 |
|
| 328 |
|
| 329 |
+
dico_data = [r.split("|") for r in Path(
|
| 330 |
+
"./wtcsay-defs.txt").read_text().splitlines()]
|
| 331 |
+
|
| 332 |
+
dico_data = {
|
| 333 |
+
r[1]: {'sino': r[2], 'pi': r[3], 'def': r[4]}
|
| 334 |
+
for r in dico_data if len(r) >= 5 and r[1]
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def def_from_soundpath(path: str):
|
| 339 |
+
basename = Path(path).name[:-4] + ".mp3"
|
| 340 |
+
if basename in dico_data:
|
| 341 |
+
return dico_data[basename]['def'], dico_data[basename]['sino']
|
| 342 |
+
return "", ""
|
| 343 |
+
|
| 344 |
+
|
| 345 |
def main_asr(audio_np):
|
| 346 |
hyp_gdpi = transcribe_np(audio_np) # ASR output in gdpi
|
| 347 |
hyp_ggn = convert_gdpi_to_ggn(hyp_gdpi) # parsetc -> ggn
|
|
|
|
| 353 |
|
| 354 |
# print("\n====== Top-{} Retrieval (Levenshtein on GGN no-tone) ======".format(TOPK))
|
| 355 |
results = []
|
| 356 |
+
for score, row in topk_df.iterrows():
|
| 357 |
rank = int(row["rank"])
|
| 358 |
py_ref = row["Ref_pinyin_ggn_pengim"]
|
| 359 |
+
wav_file = row["full_path"]
|
| 360 |
+
definition, tradi = def_from_soundpath(wav_file)
|
| 361 |
han = ""
|
| 362 |
if "chinese_simple" in topk_df.columns and pd.notna(row["chinese_simple"]):
|
| 363 |
han = row["chinese_simple"]
|
|
|
|
| 369 |
print(han)
|
| 370 |
# results.append({'han': han, 'pi': py_ref})
|
| 371 |
results.append({
|
| 372 |
+
'sino': f"{han}/{tradi}",
|
| 373 |
+
'pi': py_ref,
|
| 374 |
+
'def': definition,
|
| 375 |
# 'path': "path",
|
| 376 |
# 'speaker': "spkr",
|
| 377 |
# 'n_frames': 0,
|
| 378 |
+
'score': score
|
| 379 |
})
|
| 380 |
return results
|
| 381 |
|
static/assets/index-Bef3m2Pk.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
static/assets/index-CtkwHOHY.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
static/assets/index-DHYokP5o.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
html,body,#root{height:100%;width:100%;margin:0;padding:0;font-family:Arial,sans-serif;background-color:#0072bc}.app-container{display:flex;flex-direction:column;align-items:center;justify-content:center;width:100%;min-height:100%;padding:2rem;gap:2rem;box-sizing:border-box}.app-title{font-size:3rem;font-weight:900;margin-bottom:1rem;color:#222}.dictionary-card{border:2px solid #333;border-radius:1rem;padding:1.5rem 1.25rem;width:90%;max-width:400px;text-align:center;box-shadow:0 4px 12px #0003;background-color:#f9f9f9;margin-top:2rem;transition:transform .2s,box-shadow .2s}.dictionary-card:hover{transform:translateY(-5px);box-shadow:0 8px 20px #00000040}.dictionary-card .sinogramme{font-size:3rem;font-weight:700;margin-bottom:1rem;color:#222}.dictionary-card .pinyin{font-size:1.5rem;color:#555;margin-bottom:.75rem}.dictionary-card .definition{font-size:1.125rem;color:#333;line-height:1.5}.recorder-container{display:flex;flex-direction:column;align-items:center;padding:2rem;gap:1.5rem;width:100%;box-sizing:border-box}.recorder-title{font-size:3rem;font-weight:900;color:#fff;margin-bottom:1rem}.recorder-timer{font-size:2.5rem;font-weight:700;color:#fff;background-color:#0009;padding:.5rem 1rem;border-radius:.75rem;text-align:center;min-width:200px}.record-btn{display:flex;align-items:center;justify-content:center;background:transparent;border:none;border-radius:50%;padding:.5rem;cursor:pointer;transition:transform .2s}.record-btn:hover{transform:scale(1.1)}.w-20{width:5rem}.h-20{height:5rem}.sm-w-24{width:6rem}.sm-h-24{height:6rem}.md-w-28{width:7rem}.md-h-28{height:7rem}.visualizer-canvas{width:90%;max-width:800px;height:150px;border-radius:.75rem;box-shadow:0 4px 12px #0000004d;background-color:#000}.recorded-audio{margin-top:1rem;width:90%;max-width:400px}@media(max-width:480px){.app-title,.dictionary-card .sinogramme{font-size:2.25rem}.dictionary-card .pinyin{font-size:1.25rem}.dictionary-card .definition{font-size:1rem}``` .recorder-title{font-size:2rem}.recorder-timer{font-size:1.75rem}```{}}.arrow-buttons{display:flex;gap:0;border-radius:.5rem;overflow:hidden;background-color:#0072bc;transition:background .5s ease}.arrow-buttons:hover{background:linear-gradient(90deg,#0072bc,#1f84c5,#3e95ce,#5da7d7,#7bb9e0,#9acae9,#b9dcf2)}.arrow-btn{flex:1;padding:.75rem 1.5rem;font-size:1.5rem;border:none;color:#fff;background:transparent;cursor:pointer;transition:transform .2s,box-shadow .3s}.arrow-btn:hover{transform:scale(1.05);box-shadow:0 4px 8px #0003}.flashcard-container{display:flex;flex-wrap:wrap;gap:16px}.dictionary-card{border:1px solid #ccc;padding:12px;border-radius:8px;width:200px;box-shadow:0 2px 5px #0000001a}.inalco-header{background:#fff;border-bottom:1px solid #e0e0e0;padding:12px 24px;font-family:Arial,sans-serif}.inalco-header-inner{max-width:1200px;margin:auto;display:flex;align-items:center;gap:16px}.inalco-header-inner{display:flex;align-items:center;justify-content:space-between;max-width:1200px;margin:auto;padding:12px 24px}.inalco-logo{height:50px}.inalco-title{position:absolute;left:50%;transform:translate(-50%);font-size:1.6rem;font-weight:700;background:linear-gradient(90deg,#0072bc,#1f84c5,#3e95ce,#5da7d7,#7bb9e0,#9acae9,#b9dcf2);-webkit-background-clip:text;-webkit-text-fill-color:transparent;font-family:"Noto Serif CJK SC",SimSun,KaiTi,serif,Dancing Script,Brush Script MT,cursive}.header-spacer{width:50px}.app-container{max-width:1200px;margin:40px auto;padding:0 16px}.inalco-footer{background:#0d0d0d;color:#ccc;padding:40px 24px 20px;margin-top:60px;font-family:Arial,sans-serif}.inalco-footer-inner{max-width:1200px;margin:auto;display:flex;align-items:flex-start;flex-wrap:wrap;gap:20px}.inalco-footer-logo{height:50px;margin-right:16px}.inalco-footer h4{color:#fff;margin-bottom:10px}.inalco-footer a:hover{color:#fff}.flashcard-container{display:flex;flex-wrap:wrap;gap:16px;margin-top:20px}.dictionary-card{background:#f5f5f5;padding:12px 16px;border-radius:8px;box-shadow:0 2px 6px #0000001a;min-width:120px;text-align:center;transition:background .3s ease}.dictionary-card:hover{background:#dcefff;cursor:pointer}.inalco-footer-bottom{text-align:center;width:100%;margin-top:20px;color:#777;font-size:.85rem}
|
static/assets/index-DjwIwxr1.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
static/index.html
CHANGED
|
@@ -2,11 +2,11 @@
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<title>react-audio-recorder</title>
|
| 8 |
-
<script type="module" crossorigin src="/
|
| 9 |
-
<link rel="stylesheet" crossorigin href="/
|
| 10 |
</head>
|
| 11 |
<body>
|
| 12 |
<div id="root"></div>
|
|
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
+
<link rel="icon" type="image/svg+xml" href="./vite.svg" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<title>react-audio-recorder</title>
|
| 8 |
+
<script type="module" crossorigin src="./assets/index-DjwIwxr1.js"></script>
|
| 9 |
+
<link rel="stylesheet" crossorigin href="./assets/index-DHYokP5o.css">
|
| 10 |
</head>
|
| 11 |
<body>
|
| 12 |
<div id="root"></div>
|
wtcsay-defs.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|