-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (49 loc) · 1.81 KB
/
main.cpp
File metadata and controls
58 lines (49 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <thread>
#include "danmaku.h"
#include "SpeechRecognition.h"
std::thread danmakuThread;
void syncDanmaku(SpeechRecognition &asr) {
while (!isWtfInited()) {
std::cout << "Waiting for danmaku render to start...\n";
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
std::cout << "Danmaku render initialized.\n";
while (true) {
const auto subtitle = asr.getSubtitle();
if (auto text = subtitle.getText(); !text.empty()) {
if (isWtfInited()) {
if (subtitle.getLang() == "<|zh|>") {
addDanmaku(utf8_to_wstring(text)); // 中文使用默认字体大小 30
} else {
if (auto translation = asr.getTranslate(text); !translation.empty() && text != translation && needTranslate()) {
addDanmaku(utf8_to_wstring(translation)); // 中文翻译使用默认字体大小 30
} else {
addDanmaku(utf8_to_wstring(text), 20); // 没有翻译时,原文也使用小号字体 20
}
}
}
}
// Add a small delay to prevent busy-waiting
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
int main() {
// 切换代码页
SetConsoleOutputCP(65001);
// 初始化 ASR 线程
SpeechRecognition asr("./config.json");
asr.init();
asr.start();
// 初始化同步线程
danmakuThread = std::thread(&syncDanmaku, std::ref(asr));
// 初始化弹幕渲染线程
auto screen_size = getScreenResolution();
initDanmaku(screen_size.first, screen_size.second, L"RealtimeBilingualSubtitle");
// 结束线程
if (danmakuThread.joinable()) {
danmakuThread.join();
}
asr.stop();
destroyDanmaku();
return 0;
}