generated from obsproject/obs-plugintemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump whisper, clblast, add buffered output (#90)
* Bump whisper, clblast, add buffered output * Update CPU_OR_CUDA environment variable error messages * Update Cublas validation in Package-Windows.ps1 and initialize function in captions-thread.h * Update Cublas validation and fix typo in Package-Windows.ps1 * Update default whisper model path to Whisper Tiny English (74Mb) * Update translation strings for multiple locales
- Loading branch information
Showing
27 changed files
with
528 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#ifndef CAPTIONS_THREAD_H | ||
#define CAPTIONS_THREAD_H | ||
|
||
#include <queue> | ||
#include <vector> | ||
#include <chrono> | ||
#include <thread> | ||
#include <mutex> | ||
#include <condition_variable> | ||
#include <functional> | ||
#include <string> | ||
|
||
#include <obs.h> | ||
|
||
#include "plugin-support.h" | ||
|
||
class CaptionMonitor { | ||
public: | ||
// default constructor | ||
CaptionMonitor() = default; | ||
|
||
~CaptionMonitor() | ||
{ | ||
{ | ||
std::lock_guard<std::mutex> lock(queueMutex); | ||
stop = true; | ||
} | ||
condVar.notify_all(); | ||
workerThread.join(); | ||
} | ||
|
||
void initialize(std::function<void(const std::string &)> callback_, size_t maxSize_, | ||
std::chrono::seconds maxTime_) | ||
{ | ||
this->callback = callback_; | ||
this->maxSize = maxSize_; | ||
this->maxTime = maxTime_; | ||
this->initialized = true; | ||
this->workerThread = std::thread(&CaptionMonitor::monitor, this); | ||
} | ||
|
||
void addWords(const std::vector<std::string> &words) | ||
{ | ||
{ | ||
std::lock_guard<std::mutex> lock(queueMutex); | ||
for (const auto &word : words) { | ||
wordQueue.push_back(word); | ||
} | ||
this->newDataAvailable = true; | ||
} | ||
condVar.notify_all(); | ||
} | ||
|
||
private: | ||
void monitor() | ||
{ | ||
obs_log(LOG_INFO, "CaptionMonitor::monitor"); | ||
auto startTime = std::chrono::steady_clock::now(); | ||
while (true) { | ||
std::unique_lock<std::mutex> lock(this->queueMutex); | ||
// wait for new data or stop signal | ||
this->condVar.wait(lock, | ||
[this] { return this->newDataAvailable || this->stop; }); | ||
|
||
if (this->stop) { | ||
break; | ||
} | ||
|
||
if (this->wordQueue.empty()) { | ||
continue; | ||
} | ||
|
||
// emit up to maxSize words from the wordQueue | ||
std::vector<std::string> emitted; | ||
while (!this->wordQueue.empty() && emitted.size() <= this->maxSize) { | ||
emitted.push_back(this->wordQueue.front()); | ||
this->wordQueue.pop_front(); | ||
} | ||
// emit the caption, joining the words with a space | ||
std::string output; | ||
for (const auto &word : emitted) { | ||
output += word + " "; | ||
} | ||
this->callback(output); | ||
// push back the words that were emitted, in reverse order | ||
for (auto it = emitted.rbegin(); it != emitted.rend(); ++it) { | ||
this->wordQueue.push_front(*it); | ||
} | ||
|
||
if (this->wordQueue.size() >= this->maxSize || | ||
std::chrono::steady_clock::now() - startTime >= this->maxTime) { | ||
// flush the queue if it's full or we've reached the max time | ||
size_t words_to_flush = | ||
std::min(this->wordQueue.size(), this->maxSize); | ||
for (size_t i = 0; i < words_to_flush; ++i) { | ||
wordQueue.pop_front(); | ||
} | ||
startTime = std::chrono::steady_clock::now(); | ||
} | ||
|
||
newDataAvailable = false; | ||
} | ||
obs_log(LOG_INFO, "CaptionMonitor::monitor: done"); | ||
} | ||
|
||
std::deque<std::string> wordQueue; | ||
std::thread workerThread; | ||
std::mutex queueMutex; | ||
std::condition_variable condVar; | ||
std::function<void(std::string)> callback; | ||
size_t maxSize; | ||
std::chrono::seconds maxTime; | ||
bool stop; | ||
bool initialized = false; | ||
bool newDataAvailable = false; | ||
}; | ||
|
||
#endif // CAPTIONS_THREAD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.