diff options
| author | yum <yum.food.vr@gmail.com> | 2023-09-09 23:18:32 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2023-09-09 23:18:32 -0700 |
| commit | 9924a141b0b1266671915be12e21df6c8f4c5366 (patch) | |
| tree | 4b29e5e06e2183ab2fe4707ec84786f245f96004 | |
| parent | ae866f553d3db67030e37ce315707d72982f4063 (diff) | |
Browser source now shows preview text as slightly transparent
Improves viewer experience.
| -rw-r--r-- | BrowserSource/index.html | 49 | ||||
| -rw-r--r-- | GUI/GUI/GUI/BrowserSource.cpp | 12 | ||||
| -rw-r--r-- | GUI/GUI/GUI/Frame.cpp | 10 | ||||
| -rw-r--r-- | GUI/GUI/GUI/Transcript.cpp | 11 | ||||
| -rw-r--r-- | GUI/GUI/GUI/Transcript.h | 3 | ||||
| -rw-r--r-- | Scripts/transcribe_v2.py | 3 |
6 files changed, 77 insertions, 11 deletions
diff --git a/BrowserSource/index.html b/BrowserSource/index.html index 96692cf..28053e3 100644 --- a/BrowserSource/index.html +++ b/BrowserSource/index.html @@ -11,11 +11,33 @@ font-family: 'Noto Sans Mono', monospace; font-size: 96px; font-weight: 3200; - color: #000; + /* xdd */ + /* https://stackoverflow.com/a/55097644 */ + text-shadow: 0.0px 10.0px 0.02px #000, 9.8px 2.1px 0.02px #000, 4.2px + -9.1px 0.02px #000, -8.0px -6.0px 0.02px #000, -7.6px 6.5px 0.02px + #000, 4.8px 8.8px 0.02px #000, 9.6px -2.8px 0.02px #000, -0.7px -10.0px + 0.02px #000, -9.9px -1.5px 0.02px #000, -3.5px 9.4px 0.02px #000, 8.4px + 5.4px 0.02px #000, 7.1px -7.0px 0.02px #000, -5.4px -8.4px 0.02px #000, + -9.4px 3.5px 0.02px #000, 1.4px 9.9px 0.02px #000, 10.0px 0.8px 0.02px + #000, 2.9px -9.6px 0.02px #000, -8.7px -4.8px 0.02px #000, -6.6px 7.5px + 0.02px #000, 5.9px 8.0px 0.02px #000, 9.1px -4.1px 0.02px #000, -2.1px + -9.8px 0.02px #000, -10.0px -0.1px 0.02px #000, -2.2px 9.8px 0.02px #000, + 9.1px 4.2px 0.02px #000, 6.1px -8.0px 0.02px #000, -6.5px -7.6px 0.02px + #000, -8.8px 4.7px 0.02px #000, 2.7px 9.6px 0.02px #000, 10.0px -0.6px + 0.02px #000, 1.5px -9.9px 0.02px #000, -9.3px -3.6px 0.02px #000, -5.5px + 8.4px 0.02px #000, 7.0px 7.2px 0.02px #000, 8.5px -5.3px 0.02px #000, + -3.4px -9.4px 0.02px #000, -9.9px 1.3px 0.02px #000, -0.8px 10.0px 0.02px + #000, 9.6px 2.9px 0.02px #000, 4.9px -8.7px 0.02px #000, -7.5px -6.7px + 0.02px #000, -8.1px 5.9px 0.02px #000, 4.0px 9.2px 0.02px #000, 9.8px + -2.0px 0.02px #000, 0.2px -10.0px 0.02px #000, -9.7px -2.3px 0.02px #000, + -4.3px 9.0px 0.02px #000, 7.9px 6.1px 0.02px #000; } - #transcript { - color: #89CFF0; - -webkit-text-stroke: 3.0px #000; + .transcript { + color: white; + } + .preview { + color: white; + opacity: 0.65; } .red_circle { height: 50px; @@ -37,7 +59,7 @@ } </style> <body> - <div id="transcript"></div> + <div id="content"></div> <script> function scrollToBottom() { window.scrollTo(0,document.body.scrollHeight); @@ -49,16 +71,23 @@ dataType: 'json', success: function(data) { var transcript = data.transcript; + var preview = data.preview; var red_circle = '<span class="red_circle"></span>'; var grey_circle = '<span class="grey_circle"></span>'; - var transcript_w_circle = transcript; + + var contentHtml = ''; + contentHtml += '<span class="transcript">' + + transcript + '</span>'; + contentHtml += '<span class="preview">' + + preview + '</span>'; if (data.is_final == 1) { - transcript_w_circle += grey_circle; + contentHtml += grey_circle; } else { - transcript_w_circle += red_circle; + contentHtml += red_circle; } - $('#transcript').html(transcript_w_circle); - $('#transcript').css("background-color", "#00000080"); + + $('#content').html(contentHtml); + $('#content').css("background-color", "#22222280"); }, error: function(jqXHR, textStatus, errorThrown) { console.error('Error getting transcript: ', textStatus, errorThrown); diff --git a/GUI/GUI/GUI/BrowserSource.cpp b/GUI/GUI/GUI/BrowserSource.cpp index 45ca7f9..fce1bee 100644 --- a/GUI/GUI/GUI/BrowserSource.cpp +++ b/GUI/GUI/GUI/BrowserSource.cpp @@ -55,11 +55,23 @@ void BrowserSource::Run(volatile bool* run) transcript_oss << segment;
}
+ std::ostringstream preview_oss;
+ std::vector<std::string> preview = transcript_->GetPreview();
+ // Hack: escape transcription to work inside JSON blob.
+ for (auto& segment : preview) {
+ size_t pos;
+ while ((pos = segment.find('"')) != std::string::npos) {
+ segment[pos] = '\'';
+ }
+ preview_oss << segment;
+ }
+
bool is_final = transcript_->IsFinalized();
std::ostringstream resp_oss;
resp_oss << "{";
resp_oss << "\"transcript\":\"" << transcript_oss.str() << "\",";
+ resp_oss << "\"preview\":\"" << preview_oss.str() << "\",";
resp_oss << "\"is_final\":" << std::to_string(is_final ? 1 : 0) << "";
resp_oss << "}";
payload = resp_oss.str();
diff --git a/GUI/GUI/GUI/Frame.cpp b/GUI/GUI/GUI/Frame.cpp index f2fb140..384f2a2 100644 --- a/GUI/GUI/GUI/Frame.cpp +++ b/GUI/GUI/GUI/Frame.cpp @@ -2383,6 +2383,16 @@ void Frame::OnAppStart(wxCommandEvent& event) { //Log(transcribe_out_, "Got transcription line! Transcript: \"{}\"", filtered_transcript);
transcript_.Set(std::move(filtered_transcript));
}
+
+ pattern = std::regex("^Preview: ");
+ if (std::regex_search(out_line, pattern)) {
+ std::string filtered_transcript = std::regex_replace(out_line, pattern, "");
+ filtered_transcript.erase(std::remove_if(filtered_transcript.begin(), filtered_transcript.end(), [](char c) {
+ return c == '\n' || c == '\r';
+ }), filtered_transcript.end());
+ //Log(transcribe_out_, "Got transcription line! Transcript: \"{}\"", filtered_transcript);
+ transcript_.SetPreview(std::move(filtered_transcript));
+ }
}
};
auto in_cb = [&](std::string& in) {
diff --git a/GUI/GUI/GUI/Transcript.cpp b/GUI/GUI/GUI/Transcript.cpp index e635343..eb798d9 100644 --- a/GUI/GUI/GUI/Transcript.cpp +++ b/GUI/GUI/GUI/Transcript.cpp @@ -11,6 +11,12 @@ void Transcript::Set(std::string&& segment) { segments_.push_back(std::move(segment));
}
+void Transcript::SetPreview(std::string&& segment) {
+ std::scoped_lock l(mu_);
+ previews_.clear();
+ previews_.push_back(std::move(segment));
+}
+
void Transcript::Clear() {
std::scoped_lock l(mu_);
segments_.clear();
@@ -21,6 +27,11 @@ std::vector<std::string> Transcript::Get() { return segments_;
}
+std::vector<std::string> Transcript::GetPreview() {
+ std::scoped_lock l(mu_);
+ return previews_;
+}
+
void Transcript::SetFinalized(bool is_finalized) {
// Accessing anything smaller than a word is always atomic.
is_finalized_ = is_finalized;
diff --git a/GUI/GUI/GUI/Transcript.h b/GUI/GUI/GUI/Transcript.h index 07cf6c0..1c18afe 100644 --- a/GUI/GUI/GUI/Transcript.h +++ b/GUI/GUI/GUI/Transcript.h @@ -11,6 +11,7 @@ public: void Append(std::string&& segment);
void Set(std::string&& segment);
+ void SetPreview(std::string&& segment);
void Clear();
// Indicate whether the transcript is "finalized", i.e. the transcription
@@ -19,10 +20,12 @@ public: void SetFinalized(bool is_finalized);
std::vector<std::string> Get();
+ std::vector<std::string> GetPreview();
bool IsFinalized();
private:
std::mutex mu_;
std::vector<std::string> segments_;
+ std::vector<std::string> previews_;
bool is_finalized_{ false };
};
diff --git a/Scripts/transcribe_v2.py b/Scripts/transcribe_v2.py index 541ff23..df333bc 100644 --- a/Scripts/transcribe_v2.py +++ b/Scripts/transcribe_v2.py @@ -672,7 +672,8 @@ def transcriptionThread(ctrl: ThreadControl): commit = ctrl.committer.getDelta() if len(commit.delta) > 0 or len(commit.preview) > 0: - print(f"Transcript: {ctrl.transcript}{commit.delta}{commit.preview}") + print(f"Transcript: {ctrl.transcript}{commit.delta}") + print(f"Preview: {commit.preview}") if cfg["enable_debug_mode"]: print(f"commit latency: {commit.latency_s}", file=sys.stderr) print(f"commit thresh: {commit.thresh_at_commit}", |
