Skip to content

Commit c5e7d69

Browse files
authored
Update asr_component.py
1 parent 7fce098 commit c5e7d69

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

education-ai-suite/smart-classroom/components/asr_component.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,32 @@ def process(self, input_generator):
176176
transcribed_text = "\n".join(transcribed_lines) + "\n"
177177

178178
else:
179-
transcribed_text = transcription["text"]
180-
ui_segments = [{
181-
"speaker": None,
182-
"text": transcribed_text,
183-
"start": 0.0,
184-
"end": 0.0
185-
}]
179+
ui_segments = []
180+
181+
if transcription.get("segments"):
182+
for sent in transcription["segments"]:
183+
text = sent["text"].strip()
184+
if not text:
185+
continue
186+
187+
start = float(sent["start"]) + float(chunk_data.get("start_time", 0.0))
188+
end = float(sent["end"]) + float(chunk_data.get("start_time", 0.0))
189+
190+
segment = {
191+
"speaker": LABEL_TEACHER, # implicit teacher
192+
"text": text,
193+
"start": start,
194+
"end": end
195+
}
196+
197+
ui_segments.append(segment)
198+
self.all_segments.append(segment)
199+
200+
self.speaker_text_len[LABEL_TEACHER] = (
201+
self.speaker_text_len.get(LABEL_TEACHER, 0) + len(text)
202+
)
203+
204+
transcribed_text = "\n".join([s["text"] for s in ui_segments]) + "\n"
186205

187206
if os.path.exists(chunk_path) and DELETE_CHUNK_AFTER_USE:
188207
os.remove(chunk_path)

0 commit comments

Comments
 (0)