summaryrefslogtreecommitdiffstats
path: root/Examples/WhisperDesktop/TranscribeDlg.cpp
diff options
context:
space:
mode:
authorKonstantin <const@const.me>2023-01-30 23:49:04 +0100
committerKonstantin <const@const.me>2023-01-30 23:49:04 +0100
commit509c0cab65b2fbfea9285cb9c67bb07c0199caf5 (patch)
tree42043b55e7ed124bac2b30c1a6d8b995d3258f84 /Examples/WhisperDesktop/TranscribeDlg.cpp
parentc33e54f0a9baa9b3ecd7b8e8884b3afac46b0867 (diff)
“Text with timestamps” output format option
Diffstat (limited to 'Examples/WhisperDesktop/TranscribeDlg.cpp')
-rw-r--r--Examples/WhisperDesktop/TranscribeDlg.cpp35
1 files changed, 26 insertions, 9 deletions
diff --git a/Examples/WhisperDesktop/TranscribeDlg.cpp b/Examples/WhisperDesktop/TranscribeDlg.cpp
index 4f4944d..742c1d4 100644
--- a/Examples/WhisperDesktop/TranscribeDlg.cpp
+++ b/Examples/WhisperDesktop/TranscribeDlg.cpp
@@ -108,7 +108,8 @@ void TranscribeDlg::printModelDescription()
void TranscribeDlg::populateOutputFormats()
{
transcribeOutFormat.AddString( L"None" );
- transcribeOutFormat.AddString( L"Text File" );
+ transcribeOutFormat.AddString( L"Text file" );
+ transcribeOutFormat.AddString( L"Text with timestamps" );
transcribeOutFormat.AddString( L"SubRip subtitles" );
transcribeOutFormat.AddString( L"WebVTT subtitles" );
}
@@ -117,8 +118,9 @@ enum struct TranscribeDlg::eOutputFormat : uint8_t
{
None = 0,
Text = 1,
- SubRip = 2,
- WebVTT = 3
+ TextTimestamps = 2,
+ SubRip = 3,
+ WebVTT = 4,
};
// CBN_SELCHANGE notification for IDC_OUTPUT_FORMAT combobox
@@ -163,10 +165,10 @@ void TranscribeDlg::onBrowseMedia()
setOutputPath( path );
}
-static const LPCTSTR outputFilters = L"Text files (*.txt)\0*.txt\0SubRip subtitles (*.srt)\0*.srt\0WebVTT subtitles (*.vtt)\0*.vtt\0\0";
-static const std::array<LPCTSTR, 3> outputExtensions =
+static const LPCTSTR outputFilters = L"Text files (*.txt)\0*.txt\0Text with timestamps (*.txt)\0*.txt\0SubRip subtitles (*.srt)\0*.srt\0WebVTT subtitles (*.vtt)\0*.vtt\0\0";
+static const std::array<LPCTSTR, 4> outputExtensions =
{
- L".txt", L".srt", L".vtt"
+ L".txt", L".txt", L".srt", L".vtt"
};
void TranscribeDlg::setOutputPath( const CString& input )
@@ -414,7 +416,9 @@ HRESULT TranscribeDlg::transcribe()
switch( format )
{
case eOutputFormat::Text:
- return writeTextFile( segments, len.countSegments, outputFile );
+ return writeTextFile( segments, len.countSegments, outputFile, false );
+ case eOutputFormat::TextTimestamps:
+ return writeTextFile( segments, len.countSegments, outputFile, true );
case eOutputFormat::SubRip:
return writeSubRip( segments, len.countSegments, outputFile );
case eOutputFormat::WebVTT:
@@ -479,14 +483,27 @@ namespace
using Whisper::sSegment;
-HRESULT TranscribeDlg::writeTextFile( const sSegment* const segments, const size_t length, CAtlFile& file )
+HRESULT TranscribeDlg::writeTextFile( const sSegment* const segments, const size_t length, CAtlFile& file, bool timestamps )
{
using namespace Whisper;
CHECK( writeUtf8Bom( file ) );
CStringA line;
for( size_t i = 0; i < length; i++ )
{
- line = skipBlank( segments[ i ].text );
+ const sSegment& seg = segments[ i ];
+
+ if( timestamps )
+ {
+ line = "[";
+ printTimeStamp( line, seg.time.begin );
+ line += " --> ";
+ printTimeStamp( line, seg.time.end );
+ line += "] ";
+ }
+ else
+ line = "";
+
+ line += skipBlank( seg.text );
line += "\r\n";
CHECK( write( file, line ) );
}