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 /GUI | |
| parent | ae866f553d3db67030e37ce315707d72982f4063 (diff) | |
Browser source now shows preview text as slightly transparent
Improves viewer experience.
Diffstat (limited to 'GUI')
| -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 |
4 files changed, 36 insertions, 0 deletions
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 };
};
|
