突然发现讯飞转写变成订阅制了,少量转写可以用Amazon Transcribe,每月60分钟免费,自己常规使用够了,用chatgpt帮我写了个从transcribe下载的json转对话形式的小python,大佬轻虐。
import json
import os
def format_time(seconds):
seconds = float(seconds)
hours = int(seconds // 3600)
minutes = int((seconds % 3600) // 60)
seconds = seconds % 60
return f"{hours:02}:{minutes:02}:{seconds:06.3f}"
def process_transcript(json_filename):
# 读取JSON文件
with open(json_filename, 'r', encoding='utf-8') as file:
json_data = json.load(file)
current_speaker = None
dialogues = []
for item in json_data['results']['items']:
if 'start_time' not in item or 'end_time' not in item:
continue
speaker_label = item['speaker_label']
content = item['alternatives'][0]['content']
start_time = item['start_time']
end_time = item['end_time']
if speaker_label != current_speaker:
dialogues.append((speaker_label, content, start_time, end_time))
current_speaker = speaker_label
else:
_, prev_content, prev_start, _ = dialogues[-1]
dialogues[-1] = (speaker_label, prev_content + content, prev_start, end_time)
# 生成TXT文件名
base_filename = os.path.splitext(json_filename)[0]
txt_filename = f"{base_filename}.txt"
with open(txt_filename, 'w', encoding='utf-8') as f:
for speaker, transcript, start, end in dialogues:
formatted_start = format_time(start)
formatted_end = format_time(end)
f.write(f"{speaker} ({formatted_start} - {formatted_end}):\n")
f.write(transcript + "\n\n")
# 假设你的JSON文件名为 'example.json'
json_filename = '1.json'
process_transcript(json_filename)
终于熬到第50天了,求大佬们给个赞,另外顺便求推荐其他靠谱便宜的录音转文字平台