```
def step_4_generate_srt_by_char_calculation(wav_dict_path):
result_srt_list = []
for index, item in enumerate(wav_dict_path):
path = item.get("path")
duration = item.get("duration")
text = item.get("text")
print(f"path:{path};duration:{duration};text:{text}")
total_count = len(text)
print(f"word_count:{total_count}")
p = re.compile("[,。]") # 正则表达式模式指定为空格、句号和问号
words_list = p.split(text)
print(f"words_list:{words_list}")
# 去空
words_list = [word for word in words_list if word]
# 减去标点符号
word_count = total_count - len(words_list)
srt_list = []
# 上一句话结束时间
end_second = 0
# 字幕保存路径
save_srt_path = os.path.join(fr"{project_path}\srt_temp", f"{get_now_time()}_{index}.srt")
for w_index, summarize in enumerate(words_list):
# 通过当前的内容占比计算得出
audio_duration = len(summarize) / word_count * duration
# 字幕序号
segment_id = w_index + 1
# 字幕开始时间
start_time = second_to_time(end_second)
# 字幕结束时间
end_time = second_to_time(end_second + audio_duration)
# 将本地的结束时间赋值,下次使用
end_second = end_second + audio_duration
segment = f"{segment_id}\n{start_time} --> {end_time}\n{summarize}\n\n"
srt_list.append(segment)
with open(save_srt_path, 'a', encoding='UTF-8') as f:
for i in srt_list:
f.writelines(i)
f.close()
result_srt_list.append(save_srt_path)
return result_srt_list
```