dlxj commited on
Commit ·
66ba09a
1
Parent(s): 09d2296
保存 trascripts.json
Browse files
examples/asr/asr_cache_aware_streaming/speech_to_text_cache_aware_streaming_infer.py
CHANGED
|
@@ -306,9 +306,8 @@ def perform_streaming(
|
|
| 306 |
|
| 307 |
if debug_mode:
|
| 308 |
current_texts = extract_transcriptions(transcribed_texts)
|
| 309 |
-
# 实时打印每个 chunk 的结果
|
| 310 |
-
print(f"
|
| 311 |
-
# logging.info(f"Streaming transcriptions: {extract_transcriptions(transcribed_texts)}")
|
| 312 |
|
| 313 |
print() # 换行
|
| 314 |
final_streaming_tran, final_streaming_timestamps = extract_transcriptions(transcribed_texts, return_timestamps=True)
|
|
@@ -481,6 +480,21 @@ def main(cfg: TranscriptionConfig):
|
|
| 481 |
for key, val in streaming_timestamps[0].items():
|
| 482 |
if key != 'timestep':
|
| 483 |
logging.info(f"Timestamps {key}: {normalize_timestamp_output(val)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
|
| 485 |
# return early for single file mode
|
| 486 |
return
|
|
|
|
| 306 |
|
| 307 |
if debug_mode:
|
| 308 |
current_texts = extract_transcriptions(transcribed_texts)
|
| 309 |
+
# 实时打印每个 chunk 的结果,每次换行
|
| 310 |
+
print(f"[Streaming Step {step_num}] {current_texts[0]}", flush=True)
|
|
|
|
| 311 |
|
| 312 |
print() # 换行
|
| 313 |
final_streaming_tran, final_streaming_timestamps = extract_transcriptions(transcribed_texts, return_timestamps=True)
|
|
|
|
| 480 |
for key, val in streaming_timestamps[0].items():
|
| 481 |
if key != 'timestep':
|
| 482 |
logging.info(f"Timestamps {key}: {normalize_timestamp_output(val)}")
|
| 483 |
+
|
| 484 |
+
# 将单文件结果写入到根目录 transcripts.json
|
| 485 |
+
output_json_path = os.path.join(os.getcwd(), "transcripts.json")
|
| 486 |
+
record = {
|
| 487 |
+
"audio_filepath": cfg.audio_file,
|
| 488 |
+
"pred_text": streaming_tran[0] if streaming_tran else "",
|
| 489 |
+
}
|
| 490 |
+
if streaming_timestamps and streaming_timestamps[0]:
|
| 491 |
+
for key, val in streaming_timestamps[0].items():
|
| 492 |
+
if key != 'timestep':
|
| 493 |
+
record[f'{key}'] = normalize_timestamp_output(val)
|
| 494 |
+
|
| 495 |
+
with open(output_json_path, "w", encoding='utf-8') as out_f:
|
| 496 |
+
out_f.write(json.dumps(record, ensure_ascii=False) + '\n')
|
| 497 |
+
logging.info(f"Results saved to {output_json_path}")
|
| 498 |
|
| 499 |
# return early for single file mode
|
| 500 |
return
|