admin管理员组文章数量:1346298
I have an .srt file where each speech segment is supposed to last a specific duration (e.g., 4 seconds). However, when I generate the speech using Google Text-to-Speech (TTS) with SSML, the resulting audio plays the same segment in a shorter time (e.g., 3 seconds).
I want to adjust the speech rate dynamically in SSML so that each segment matches its original timing. My idea is to use ffmpeg to extract the actual duration of each generated speech segment, then calculate the speech rate percentage as: generated duration speech rate = -------------------- original duration
This percentage would then be applied in SSML using the tag, like: Text to be spoken
How can I accurately measure the duration of each segment using ffmpeg, and what is the best way to apply the correct speech rate in SSML to match the original .srt timing?
I tried duration and my SSML should look like this:
f.write(f'\t<p>{break_until_start}{text}<break time="{value["break_until_next"]}ms"/></p>\n')
Code writing the SSML:
text = value['text'] start_time_ms = int(value['start_ms']) # Start time in milliseconds previous_end_ms = int(subsDict.get(str(int(key) - 1), {}).get('end_ms', 0)) # Get the previous end time gap_to_fill = max(0, start_time_ms - previous_end_ms)
text = text.replace("&", "&").replace('"', """).replace("'", "'").replace("<", "<").replace(
">", ">")
break_until_start = f'<break time="{gap_to_fill}ms"/>' if gap_to_fill > 0 else ''
f.write(f'\t<p>{break_until_start}{text}<break time="{value["break_until_next"]}ms"/></p>\n')
f.write('</speak>\n')
本文标签: pythonHow to Adjust Google TTS SSML to Match Original SRT TimingStack Overflow
版权声明:本文标题:python - How to Adjust Google TTS SSML to Match Original SRT Timing? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743825041a2545485.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论