You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
import requests |
|
from pathlib import Path |
|
|
|
# 音频文件路径 |
|
audio_path = r"G:\Work_data\workstation\Forwork-voice-txt\FireRedASR\new_pyannote\大湖口镇米湖村适配器-763882-20251101083039.mp3" |
|
|
|
# 发送请求 |
|
with open(audio_path, 'rb') as f: |
|
response = requests.post( |
|
"http://localhost:9000/transcriptions", |
|
files={"file": ("test.mp3", f, "audio/mpeg")} |
|
) |
|
|
|
# 解析结果 |
|
result = response.json() |
|
|
|
# 控制台输出 |
|
print(f"状态: {result['message']}") |
|
print(f"总片段数: {result['data']['statistics']['total_segments']}") |
|
print(f"处理耗时: {result['data']['statistics']['processing_time']}秒") |
|
print(f"\n转录结果:") |
|
|
|
# 准备文本内容 |
|
text_lines = [] |
|
|
|
for seg in result['data']['transcription']: |
|
start_sec = seg['start'] / 1000 |
|
end_sec = seg['end'] / 1000 |
|
|
|
# 控制台输出(带时间戳) |
|
print(f"[{start_sec:.2f}s - {end_sec:.2f}s] ({seg['segment_type']}) {seg['content']}") |
|
|
|
# 纯文本内容(不带时间戳) |
|
text_lines.append(seg['content']) |
|
|
|
# 保存为txt文件(与音频文件同目录) |
|
audio_file = Path(audio_path) |
|
output_txt = audio_file.parent / f"{audio_file.stem}_transcription.txt" |
|
|
|
with open(output_txt, 'w', encoding='utf-8') as f: |
|
f.write('\n'.join(text_lines)) |
|
|
|
print(f"\n转录文本已保存至: {output_txt}") |