Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SRT sequencing for real time, use ms for remainTime/delay for all… #1680

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions scenarios/cpp/windows/captioning/captioning/captioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Captioning
std::shared_ptr<AudioStreamFormat> m_format = NULL;
std::shared_ptr<BinaryFileReader> m_callback = NULL;
std::shared_ptr<PullAudioInputStream> m_stream = NULL;
int m_srtSequenceNumber = 0;
int m_srtSequenceNumber = 1;
std::optional<Caption> m_previousCaption = std::nullopt;
std::optional<Timestamp> m_previousEndTime = std::nullopt;
bool m_previousResultIsRecognized = false;
Expand Down Expand Up @@ -93,7 +93,7 @@ class Captioning
std::string retval;
if (m_userConfig->useSubRipTextCaptionFormat)
{
retval += caption.sequence + "\n";
retval += std::to_string(caption.sequence) + "\n";
}
retval += GetTimestamp(caption.begin, caption.end) + "\n";
retval += caption.text + "\n\n";
Expand Down Expand Up @@ -454,10 +454,10 @@ int main(int argc, char* argv[])
" Minimum is 20. Default is 37 (30 for Chinese).\n"
" --lines LINES Set the number of lines for a caption to LINES.\n"
" Minimum is 1. Default is 2.\n"
" --delay SECONDS How many SECONDS to delay the appearance of each caption.\n"
" Minimum is 0.0. Default is 1.0.\n"
" --remainTime SECONDS How many SECONDS a caption should remain on screen if it is not replaced by another.\n"
" Minimum is 0.0. Default is 1.0.\n\n"
" --delay MILLISECONDS How many MILLISECONDS to delay the appearance of each caption.\n"
" Minimum is 0. Default is 1000.\n"
" --remainTime MILLISECONDS How many MILLISECONDS a caption should remain on screen if it is not replaced by another.\n"
" Minimum is 0. Default is 1000.\n\n"
" --quiet Suppress console output, except errors.\n"
" --profanity OPTION Valid values: raw, remove, mask\n"
" --threshold NUMBER Set stable partial result threshold.\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="helper.h" />
<ClInclude Include="binary_file_reader.h" />
<ClInclude Include="caption_helper.h" />
<ClInclude Include="string_helper.h" />
<ClInclude Include="user_config.h" />
<ClInclude Include="wav_file_reader.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
10 changes: 5 additions & 5 deletions scenarios/csharp/dotnetcore/captioning/captioning/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Captioning
class Program
{
private UserConfig? _userConfig;
private int _srtSequenceNumber = 0;
private int _srtSequenceNumber = 1;
private Caption? _previousCaption;
private TimeSpan? _previousEndTime;
private bool _previousResultIsRecognized = false;
Expand Down Expand Up @@ -434,10 +434,10 @@ Default output mode is offline.
Minimum is 20. Default is 37 (30 for Chinese).
--lines LINES Set the number of lines for a caption to LINES.
Minimum is 1. Default is 2.
--delay SECONDS How many SECONDS to delay the appearance of each caption.
Minimum is 0.0. Default is 1.0.
--remainTime SECONDS How many SECONDS a caption should remain on screen if it is not replaced by another.
Minimum is 0.0. Default is 1.0.
--delay MILLISECONDS How many MILLISECONDS to delay the appearance of each caption.
Minimum is 0. Default is 1000.
--remainTime MILLISECONDS How many MILLISECONDS a caption should remain on screen if it is not replaced by another.
Minimum is 0. Default is 1000.
--quiet Suppress console output, except errors.
--profanity OPTION Valid values: raw, remove, mask
Default is mask.
Expand Down
26 changes: 13 additions & 13 deletions scenarios/csharp/dotnetcore/captioning/captioning/UserConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public class UserConfig
readonly public bool suppressConsoleOutput = false;
/// The captioning mode. Default is offline.
readonly public CaptioningMode captioningMode = CaptioningMode.Offline;
/// How long (in seconds) a caption should remain on screen. Default is 1.0.
/// How long (in milliseconds) a caption should remain on screen. Default is 1000.
readonly public TimeSpan remainTime;
/// How long (in seconds) to delay all caption timestamps. Default is 1.0.
/// How long (in milliseconds) to delay all caption timestamps. Default is 1000.
readonly public TimeSpan delay;
/// Output captions in SubRip Text format (default is WebVTT format).
readonly public bool useSubRipTextCaptionFormat = false;
Expand Down Expand Up @@ -203,27 +203,27 @@ public static UserConfig UserConfigFromArgs(string[] args, string usage)
CaptioningMode captioningMode = CmdOptionExists(args, "--realTime") && !CmdOptionExists(args, "--offline") ? CaptioningMode.RealTime : CaptioningMode.Offline;

string? strRemainTime = GetCmdOption(args, "--remainTime");
TimeSpan timeSpanRemainTime = TimeSpan.FromSeconds(1.0);
TimeSpan timeSpanRemainTime = TimeSpan.FromMilliseconds(1000);
if (null != strRemainTime)
{
double dblRemainTime = Double.Parse(strRemainTime);
if (dblRemainTime < 0.0)
int intRemainTime = Int32.Parse(strRemainTime);
if (intRemainTime < 0)
{
dblRemainTime = 1.0;
intRemainTime = 1000;
}
timeSpanRemainTime = TimeSpan.FromSeconds(dblRemainTime);
timeSpanRemainTime = TimeSpan.FromMilliseconds(intRemainTime);
}

string? strDelay = GetCmdOption(args, "--delay");
TimeSpan timeSpanDelay = TimeSpan.FromSeconds(1.0);
TimeSpan timeSpanDelay = TimeSpan.FromMilliseconds(1000);
if (null != strDelay)
{
double dblDelay = Double.Parse(strDelay);
if (dblDelay < 0.0)
int intDelay = Int32.Parse(strDelay);
if (intDelay < 0)
{
dblDelay = 1.0;
intDelay = 1000;
}
timeSpanDelay = TimeSpan.FromSeconds(dblDelay);
timeSpanDelay = TimeSpan.FromMilliseconds(intDelay);
}

string? strMaxLineLength = GetCmdOption(args, "--maxLineLength");
Expand Down Expand Up @@ -270,4 +270,4 @@ public static UserConfig UserConfigFromArgs(string[] args, string usage)
);
}
}
}
}
2 changes: 1 addition & 1 deletion scenarios/java/jre/console/captioning/Captioning.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class Captioning
{
UserConfig _userConfig;
int _srtSequenceNumber = 0;
int _srtSequenceNumber = 1;
Optional<Caption> _previousCaption = Optional.empty();
Optional<Instant> _previousEndTime = Optional.empty();
boolean _previousResultIsRecognized = false;
Expand Down
10 changes: 5 additions & 5 deletions scenarios/python/console/captioning/captioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
Minimum is 20. Default is 37 (30 for Chinese).
--lines LINES Set the number of lines for a caption to LINES.
Minimum is 1. Default is 2.
--delay SECONDS How many SECONDS to delay the appearance of each caption.
Minimum is 0.0. Default is 1.0.
--remainTime SECONDS How many SECONDS a caption should remain on screen if it is not replaced by another.
Minimum is 0.0. Default is 1.0.
--delay MILLISECONDS How many MILLISECONDS to delay the appearance of each caption.
Minimum is 0. Default is 1000.
--remainTime MILLISECONDS How many MILLISECONDS a caption should remain on screen if it is not replaced by another.
Minimum is 0. Default is 1000.
--quiet Suppress console output, except errors.
--profanity OPTION Valid values: raw, remove, mask
Default is mask.
Expand All @@ -79,7 +79,7 @@
class Captioning(object) :
def __init__(self) :
self._user_config = user_config_helper.user_config_from_args(USAGE)
self._srt_sequence_number = 0
self._srt_sequence_number = 1
self._previous_caption : Optional[caption_helper.Caption] = None
self._previous_end_time : Optional[time] = None
self._previous_result_is_recognized = False
Expand Down
20 changes: 10 additions & 10 deletions scenarios/python/console/captioning/user_config_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ def user_config_from_args(usage : str) -> helper.Read_Only_Dict :

captioning_mode = CaptioningMode.REALTIME if cmd_option_exists("--realtime") and not cmd_option_exists("--offline") else CaptioningMode.OFFLINE

td_remain_time = timedelta(seconds=1.0)
td_remain_time = timedelta(milliseconds=1000)
s_remain_time = get_cmd_option("--remainTime")
if s_remain_time is not None :
flt_remain_time = float(s_remain_time)
if flt_remain_time < 0.0 :
flt_remain_time = 1.0
td_remain_time = timedelta(seconds=flt_remain_time)
int_remain_time = float(s_remain_time)
if int_remain_time < 0 :
int_remain_time = 1000
td_remain_time = timedelta(milliseconds=int_remain_time)

td_delay = timedelta(seconds=1.0)
td_delay = timedelta(milliseconds=1000)
s_delay = get_cmd_option("--delay")
if s_delay is not None :
flt_delay = float(s_delay)
if flt_delay < 0.0 :
flt_delay = 1.0
td_delay = timedelta(seconds=flt_delay)
int_delay = float(s_delay)
if int_delay < 0 :
int_delay = 1000
td_delay = timedelta(milliseconds=int_delay)

int_max_line_length = helper.DEFAULT_MAX_LINE_LENGTH_SBCS
s_max_line_length = get_cmd_option("--maxLineLength")
Expand Down