-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeech_to_obs.js
119 lines (110 loc) · 2.93 KB
/
speech_to_obs.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const puppeteer = require("puppeteer-core");
const customArgs = [
"--use-fake-ui-for-media-stream",
"--window-size=0,0", // Launch baby window for fun.
"--window-position=0,0",
];
if (process.env["PROXY_SERVER"]) {
customArgs.push(`--proxy-server=${process.env["PROXY_SERVER"]}`);
}
const OBSWebSocket = require("obs-websocket-js");
const obs = new OBSWebSocket();
obs.connect({ address: "localhost:4444" }).then(() => {
console.log("opened");
obs.sendCallback(
"SetTextGDIPlusProperties",
{
source: "jimaku_fixed",
text: "",
},
console.log
);
obs.sendCallback(
"SetTextGDIPlusProperties",
{
source: "jimaku_not_fixed",
text: "",
},
console.log
);
});
puppeteer
.launch({
executablePath: process.env["CHROME_PATH"]
? process.env["CHROME_PATH"]
: null,
headless: false,
devtools: true,
args: customArgs,
ignoreDefaultArgs: ["--mute-audio"],
})
.then(async (browser) => {
const page = await browser.newPage();
await page.exposeFunction("logging", (text) => {
console.log(text);
});
await page.exposeFunction("handleRecognized", (text) => {
obs.sendCallback(
"SetTextGDIPlusProperties",
{
source: "jimaku_not_fixed",
text: text,
},
(prop) => {
console.log(text);
}
);
});
await page.exposeFunction("handleRecognizedFixed", (text) => {
obs.sendCallback(
"SetTextGDIPlusProperties",
{
source: "jimaku_fixed",
text: text,
},
(prop) => {
console.log("fixed", text);
}
);
obs.sendCallback(
"SetTextGDIPlusProperties",
{
source: "jimaku_not_fixed",
text: "",
},
() => {}
);
});
await page.evaluate(async () => {
return new Promise((resolve, reject) => {
var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = true;
recognition.maxAlternatives = 1;
recognition.lang = "ja";
recognition.onresult = function (event) {
console.log(event);
for (var i = event.resultIndex; i < event.results.length; ++i) {
if (event.results[i].isFinal) {
window.handleRecognizedFixed(event.results[i][0].transcript);
} else {
window.handleRecognized(event.results[i][0].transcript);
}
}
};
recognition.onend = function (event) {
console.log("onend", event);
window.logging("end");
resolve();
};
recognition.onstart = function (event) {
console.log("onstart", event);
window.logging("onstarted");
};
recognition.start();
window.logging("recognition.started");
console.log("hoge");
});
});
await browser.close();
});