Vadym Myroshnyk commited on
Commit ·
2bb92e4
1
Parent(s): 5a4fcc5
save
Browse files
service/oral/oral_service.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
from service.oral.repeat_lines_loader import load_repeat_lines
|
| 4 |
from service.oral.speech_to_text import transcribe_audio
|
| 5 |
from service.oral.variants_matcher import expand_variants
|
| 6 |
from utils.audio_files import get_audio_structure
|
| 7 |
from utils.comparator import highlight_fuzzy_diff, get_feedback
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
def oral_exercise(audio_dir: str, expected_result_dir: str):
|
|
@@ -59,12 +59,12 @@ def oral_exercise(audio_dir: str, expected_result_dir: str):
|
|
| 59 |
@gr.render(inputs=[week_dropdown, current_index, sentence_state, transcriptions])
|
| 60 |
def render_repeat_section(week, index, sentences, texts):
|
| 61 |
text_path = f"{expected_result_dir}/{week.lower()}.txt"
|
| 62 |
-
lines =
|
| 63 |
|
| 64 |
index = max(0, min(index, len(lines) - 1)) if lines else 0
|
| 65 |
|
| 66 |
if lines:
|
| 67 |
-
text = lines[index]
|
| 68 |
variants = expand_variants(text)
|
| 69 |
sentences = [(index, variants)]
|
| 70 |
texts = [""] if len(texts) < len(sentences) else texts
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
| 3 |
from service.oral.speech_to_text import transcribe_audio
|
| 4 |
from service.oral.variants_matcher import expand_variants
|
| 5 |
from utils.audio_files import get_audio_structure
|
| 6 |
from utils.comparator import highlight_fuzzy_diff, get_feedback
|
| 7 |
+
from utils.dialogue_loader import load_dialogue_lines
|
| 8 |
|
| 9 |
|
| 10 |
def oral_exercise(audio_dir: str, expected_result_dir: str):
|
|
|
|
| 59 |
@gr.render(inputs=[week_dropdown, current_index, sentence_state, transcriptions])
|
| 60 |
def render_repeat_section(week, index, sentences, texts):
|
| 61 |
text_path = f"{expected_result_dir}/{week.lower()}.txt"
|
| 62 |
+
lines = load_dialogue_lines(text_path)
|
| 63 |
|
| 64 |
index = max(0, min(index, len(lines) - 1)) if lines else 0
|
| 65 |
|
| 66 |
if lines:
|
| 67 |
+
speaker, text = lines[index]
|
| 68 |
variants = expand_variants(text)
|
| 69 |
sentences = [(index, variants)]
|
| 70 |
texts = [""] if len(texts) < len(sentences) else texts
|
service/oral/repeat_lines_loader.py
DELETED
|
@@ -1,7 +0,0 @@
|
|
| 1 |
-
def load_repeat_lines(path: str) -> list[str]:
|
| 2 |
-
try:
|
| 3 |
-
with open(path, "r", encoding="utf-8") as f:
|
| 4 |
-
lines = [line.strip() for line in f if line.strip()]
|
| 5 |
-
return lines
|
| 6 |
-
except FileNotFoundError:
|
| 7 |
-
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|