add repetition filter and refactor host
This commit is contained in:
parent
e92d260b31
commit
4660be2efb
@ -119,6 +119,8 @@ namespace
|
||||
default:
|
||||
{
|
||||
ThreadParam tp = *(ThreadParam*)buffer;
|
||||
buffer[bytesRead] = 0;
|
||||
buffer[bytesRead + 1] = 0;
|
||||
DispatchText(tp, buffer + sizeof(tp), bytesRead - sizeof(tp));
|
||||
}
|
||||
break;
|
||||
|
@ -5,14 +5,7 @@
|
||||
#include "textthread.h"
|
||||
#include "const.h"
|
||||
|
||||
TextThread::TextThread(ThreadParam tp, DWORD status) :
|
||||
deletionEvent(CreateEventW(nullptr, FALSE, FALSE, NULL)),
|
||||
flushThread([&]() { while (WaitForSingleObject(deletionEvent, 100) == WAIT_TIMEOUT) Flush(); }),
|
||||
timestamp(GetTickCount()),
|
||||
Output(nullptr),
|
||||
tp(tp),
|
||||
status(status)
|
||||
{}
|
||||
TextThread::TextThread(ThreadParam tp, DWORD status) : tp(tp), status(status) {}
|
||||
|
||||
TextThread::~TextThread()
|
||||
{
|
||||
@ -30,7 +23,7 @@ std::wstring TextThread::GetStore()
|
||||
void TextThread::Flush()
|
||||
{
|
||||
LOCK ttLock(ttMutex);
|
||||
if (timestamp - GetTickCount() < 250 || buffer.size() == 0) return; // TODO: let user change delay before sentence is flushed
|
||||
if (buffer.size() < 400 && (timestamp - GetTickCount() < 250 || buffer.size() == 0)) return; // TODO: let user change delay before sentence is flushed
|
||||
std::wstring sentence;
|
||||
if (status & USING_UNICODE)
|
||||
{
|
||||
@ -43,6 +36,7 @@ void TextThread::Flush()
|
||||
delete[] converted;
|
||||
}
|
||||
AddSentence(sentence);
|
||||
memset(buffer.data(), 0, buffer.size());
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
@ -56,6 +50,8 @@ void TextThread::AddSentence(std::wstring sentence)
|
||||
void TextThread::AddText(const BYTE *con, int len)
|
||||
{
|
||||
LOCK ttLock(ttMutex);
|
||||
// Artikash 8/27/2018: add repetition filter
|
||||
if (len > 6 && buffer.data() && (strstr(buffer.data(), (const char*)con) || wcsstr((const wchar_t*)buffer.data(), (const wchar_t*)con))) return;
|
||||
buffer.insert(buffer.end(), con, con + len);
|
||||
timestamp = GetTickCount();
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ private:
|
||||
|
||||
std::vector<char> buffer;
|
||||
std::wstring storage;
|
||||
|
||||
std::recursive_mutex ttMutex;
|
||||
HANDLE deletionEvent;
|
||||
std::thread flushThread;
|
||||
DWORD timestamp;
|
||||
|
||||
HANDLE deletionEvent = CreateEventW(nullptr, FALSE, FALSE, NULL);
|
||||
std::thread flushThread = std::thread([&]() { while (WaitForSingleObject(deletionEvent, 100) == WAIT_TIMEOUT) Flush(); });
|
||||
DWORD timestamp = GetTickCount();
|
||||
|
||||
ThreadOutputCallback Output;
|
||||
ThreadParam tp;
|
||||
|
Loading…
Reference in New Issue
Block a user