TextOutput onCues called multiple times with same cue text with segmented WebVTT subtitles
Our stream provider recently changed the way the subtitles are segmented so that a subtitle segment length is the same as the video segment. So now one .vtt file contains subtitles for a 10 second period. Now there can be multiple subtitle segments that contain the same cue if the cue should be visible in 2 different segments.
Example .vtt segments: seg-38.vtt WEBVTT
28 00:05:47.160 --> 00:05:50.000 This line is repeated twice
seg-39.vtt WEBVTT
28 00:05:47.160 --> 00:05:50.000 This line is repeated twice
29 00:05:52.680 --> 00:05:54.320 Some other line that is fine
The issue with the onCues getting called twice with the same cue causes problems because we use the onCues callback to feed the cues to the Text-To-Speech engine and now users are complaining that they hear the same line twice.
I was thinking that I could check if the subtitle number (28 in the example above) matches the previous cue's number and skip the duplicate one based on that but there seems to be no way to get that line number from the cue that's provided in the onCues method.
Do you have any ideas for a workaround for this issue. At first I was thinking about storing the previous cue and checking if the next cue text matches the previous one and then skipping it if it matches but there may be cases where it is intended to have the same text repeat multiple times in a row so that won't really work. I would need to be able to compare the start/end times or subtitle numbers but those aren't provided to the method.
At first I was thinking about storing the previous cue and checking if the next cue text matches the previous one and then skipping it if it matches but there may be cases where it is intended to have the same text repeat multiple times in a row so that won't really work.
I think this will work actually, because of the way TextOutput uses an empty List
When seeing the subtitles on-screen, there's expected to be no visual difference between these call sequences:
textOutput.onCues(["cue 1"]);
textOutput.onCues([]);
textOutput.onCues(["cue 2"]);
textOutput.onCues([]);
textOutput.onCues(["cue 1"]);
textOutput.onCues([]);
textOutput.onCues(["cue 2"]);
// cue 2 is already shown on-screen, so showing it again is a no-op
textOutput.onCues(["cue 2"]);
textOutput.onCues([]);
If you want your TextOutput implementation to mimic this behaviour then it seems the right thing to do is only 'speak' subtitles when they're different to the previous parameter.
If a content provider wants subtitle content to 'repeat' in a way that's visible to the viewer they're going to need to make it disappear and reappear (or change some other property e.g. position, color, etc). And these changes will be visible to your memoization implementation:
textOutput.onCues(["cue 1"]);
textOutput.onCues([]);
textOutput.onCues(["cue 1"]);
Note that you'd still be making a lot of assumptions (which may be completely fine if you control the content, just want to call them out).
e.g. some subtitles are 'typed' onto screen letter-by-letter and thus the call sequence ends up being something like this, which i imagine would upset your TTS engine:
textOutput.onCues(["c"])
textOutput.onCues(["cu"])
textOutput.onCues(["cue"])
textOutput.onCues(["cue "])
textOutput.onCues(["cue 1"])
And similarly you probably don't want to re-speak subtitles when a second cue is added to the list (i.e. appears on-screen while the first cue stays visible). There the call sequence is something like:
textOutput.onCues(["cue 1"])
// Here you probably only want to say "cue 2"
textOutput.onCues(["cue 1", "cue 2"])
You can probably solve the latter case by being careful about how you memoize the cues. The former case seems much harder to solve, it might be easier just to assume your content won't do that...
Thanks for the fast reply and explanation. Our subtitles are authored so that there is only one subtitle on screen at a time and they should be in a format that is readable by text-to-speech so there won't be those kind of cases that you mentioned in your examples.
I didn't notice at first that the method will be called with an empty array when there is a change from one subtitle to another so this should actually work just fine in our case as long as there is at least a small gap in the timestamps.