make duration proportional to length of segment

This commit is contained in:
j 2023-05-16 09:42:16 +01:00
commit 07034fe8dc
2 changed files with 24 additions and 8 deletions

View file

@ -137,3 +137,18 @@ function onVisibilityChange(el, callback) {
function parseTime(value) {
return value.split(":").map(p => parseFloat(p)).reduce((c, p) => { return c*60 + p}, 0)
}
function splitText(text, duration) {
var parts = []
text = text.replace(/<br\ \/>/g, '<br>').replace(/<br\/>/g, '<br>')
var length = text.replace(/<br>/g, '').length
var texts = text.split('<br>')
texts.forEach(part => {
parts.push({
value: part.trim(),
duration: duration / length * part.length
})
})
return parts
}