Skip to content

Commit 56439a4

Browse files
authored
Merge pull request #57 from Kruiser8/develop
Update for v1.6.2
2 parents 8ef3c20 + d52278b commit 56439a4

6 files changed

Lines changed: 170 additions & 10 deletions

File tree

js/Documentation.md

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Each handler provides its own triggers and actions that can be used in a trigger
137137
* [Actions](#obs-actions)
138138
+ [OBS AddSceneItem](#obs-addsceneitem)
139139
+ [OBS CurrentScene](#obs-currentscene)
140+
+ [OBS Flip](#obs-flip)
140141
+ [OBS IsSceneSourceVisible](#obs-isscenesourcevisible)
141142
+ [OBS IsSourceActive](#obs-issourceactive)
142143
+ [OBS Media Duration](#obs-media-duration)
@@ -148,6 +149,7 @@ Each handler provides its own triggers and actions that can be used in a trigger
148149
+ [OBS Mute](#obs-mute)
149150
+ [OBS Position](#obs-position)
150151
+ [OBS Refresh](#obs-refresh)
152+
+ [OBS Rotate](#obs-rotate)
151153
+ [OBS SaveReplayBuffer](#obs-savereplaybuffer)
152154
+ [OBS Scene](#obs-scene)
153155
+ [OBS SceneSource](#obs-scenesource)
@@ -159,6 +161,7 @@ Each handler provides its own triggers and actions that can be used in a trigger
159161
+ [OBS Source URL](#obs-source-url)
160162
+ [OBS StartReplayBuffer](#obs-startreplaybuffer)
161163
+ [OBS StartStream](#obs-startstream)
164+
+ [OBS Stats](#obs-stats)
162165
+ [OBS StopReplayBuffer](#obs-stopreplaybuffer)
163166
+ [OBS StopStream](#obs-stopstream)
164167
+ [OBS TakeSourceScreenshot](#obs-takesourcescreenshot)
@@ -1432,9 +1435,11 @@ Use this to determine all global variables in Kruiz Control.
14321435
**Format** | `Globals <name>`
14331436
**Example** | `Globals MyGlobals`
14341437

1438+
##### Example Usage
1439+
14351440
<table>
14361441
<tr>
1437-
<td>Example Usage: Sends all global variable names chat</td>
1442+
<td>Sends all global variable names chat</td>
14381443
</tr>
14391444
<tr>
14401445
<td>
@@ -1454,7 +1459,7 @@ Chat Send {value}
14541459

14551460
<table>
14561461
<tr>
1457-
<td>Example Usage: Sends all global variable names and values to an example API</td>
1462+
<td>Sends all global variable names and values to an example API</td>
14581463
</tr>
14591464
<tr>
14601465
<td>
@@ -1682,6 +1687,15 @@ Enables the ability to interact with and respond to OBS.
16821687

16831688
***
16841689

1690+
#### OBS Flip
1691+
| | |
1692+
------------ | -------------
1693+
**Info** | Used to flip a source in OBS.
1694+
**Format** | `OBS Flip <scene> <source> <x/y>`
1695+
**Example** | `OBS Flip Webcam Camera x`
1696+
1697+
***
1698+
16851699
#### OBS IsSceneSourceVisible
16861700
| | |
16871701
------------ | -------------
@@ -1811,6 +1825,17 @@ Enables the ability to interact with and respond to OBS.
18111825

18121826
***
18131827

1828+
#### OBS Rotate
1829+
| | |
1830+
------------ | -------------
1831+
**Info** | Used to rotate a source in SLOBS. `<degree>` is any number (decimals allowed). This resets the base rotation to 0 before applying the rotation.
1832+
**Format** | `SLOBS Rotate <scene> <source> <degree>`
1833+
**Example** | `SLOBS Rotate Webcam Camera 90`
1834+
1835+
_Note: If you want the source to spin in place, right-click the source and select `Transform` > `Edit Transform`. Change the `Positional Alignment` to `Center`._
1836+
1837+
***
1838+
18141839
#### OBS Scene
18151840
| | |
18161841
------------ | -------------
@@ -1923,6 +1948,48 @@ _Note: The browser source does not need to be in current/active scene for this t
19231948
**Format** | `OBS StartStream`
19241949
**Example** | `OBS StartStream`
19251950

1951+
***
1952+
1953+
#### OBS Stats
1954+
| | |
1955+
------------ | -------------
1956+
**Info** | Used to retrieve OBS statistics.
1957+
**Format** | `OBS Stats`
1958+
**Example** | `OBS Stats`
1959+
1960+
##### Parameters
1961+
| | |
1962+
------------ | -------------
1963+
**cpu** | Percent CPU in use by OBS.
1964+
**memory** | Amount of memory in MB currently being used by OBS.
1965+
**disk_space** | Available disk space on the device being used for recording storage.
1966+
**fps** | Current FPS being rendered.
1967+
**average_render_time** | Average time in milliseconds that OBS is taking to render a frame.
1968+
**render_skipped_frames** | Number of rendered frames skipped by OBS (render frames are frames produced even when not recording or streaming).
1969+
**output_skipped_frames** | Number of output frames skipped by OBS (the frames being recorded or streamed).
1970+
**data** | The entire [OBS Websocket GetStats output](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#getstats).
1971+
1972+
##### Example Usage
1973+
1974+
<table>
1975+
<tr>
1976+
<td>Sends OBS statistics to chat</td>
1977+
</tr>
1978+
<tr>
1979+
<td>
1980+
1981+
```m
1982+
OnInit
1983+
OBS Stats
1984+
Error "OBS is using {cpu}% CPU and {memory}MB RAM."
1985+
Error "OBS is rendering {fps} FPS, skipping {render_skipped_frames} frames total ({output_skipped_frames} skipped during output). Each frames takes an average of {average_render_time}ms to render."
1986+
```
1987+
1988+
</td>
1989+
</tr>
1990+
</table>
1991+
1992+
19261993
***
19271994

19281995
#### OBS StopReplayBuffer
@@ -2751,9 +2818,12 @@ None at the moment.
27512818
#### TTS
27522819
| | |
27532820
------------ | -------------
2754-
**Info** | Used to read a message with the specified voice. `<voice>` is the name of a voice from your computer's narration system. You can check the available voices by using [`TTS Voices`](#tts-voices). `<volume>` is the audio volume. `<wait/nowait>` determines whether or not the script waits until the audio is done playing before completing the next action. `<message>` is the text to read in the audio.
2755-
**Format** | `TTS <voice> <volume> <wait/nowait> <message>`
2756-
**Example** | `TTS "Microsoft David - English (United States)" 70 wait "Hey there!"`
2821+
**Info** | Used to read a message with the specified voice. `<voice>` is the name of a voice from your computer's narration system. You can check the available voices by using [`TTS Voices`](#tts-voices). `<volume>`, `<pitch>`, and `<rate>` are all numbers between 0 and 100. If a non-numerical value is provided, the default is used. `<wait/nowait>` determines whether or not the script waits until the audio is done playing before completing the next action. `<message>` is the text to read in the audio.
2822+
**Format** | `TTS <voice> <volume> <pitch> <rate> <wait/nowait> <message>`
2823+
**Example** | `TTS "Microsoft David - English (United States)" 70 50 20 wait "Hey there!"`
2824+
**Example w/ default pitch & rate** | `TTS "Microsoft David - English (United States)" 70 - - wait "Hey there!"`
2825+
2826+
_Note: For backwards compatibility, the `<pitch>` and `<rate>` inputs are optional, but they are both required if one of them is provided._
27572827

27582828
***
27592829

@@ -2774,9 +2844,11 @@ Use this to determine the available voices on your computer.
27742844
**Format** | `TTS Voices <name>`
27752845
**Example** | `TTS Voices MyVoices`
27762846

2847+
##### Example Usage
2848+
27772849
<table>
27782850
<tr>
2779-
<td>Example Usage: Sends all voice options to chat</td>
2851+
<td>Sends all voice options to chat</td>
27802852
</tr>
27812853
<tr>
27822854
<td>

js/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Do stuff if the document is fully loaded
22
$(document).ready(async function() {
3+
var version = await readFile("version.txt");
4+
console.error(`Kruiz Control ${version.trim()} Initialized`);
35
var data = await readFile("triggers.txt");
46
await readTriggerFile(data);
57
});
@@ -25,8 +27,12 @@ async function readFileTriggers(data) {
2527
for (var i = 0; i < lines.length; i++) {
2628
var line = lines[i];
2729
if (!line.startsWith('#') && line.trim().length > 0) {
28-
var input = await readFile('triggers/' + line);
29-
controller.parseInput(input, true);
30+
try {
31+
var input = await readFile('triggers/' + line);
32+
controller.parseInput(input, true);
33+
} catch (error) {
34+
console.error(`Check that the ${line} file exists in the triggers folder`);
35+
}
3036
}
3137
}
3238

js/obs/obs-wrapper.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
function connectOBSWebsocket(address, password, obsHandler, onSwitchScenes, onTransitionBegin, onStreamStateChange, onCustomMessage, onOBSSourceVisibility, onOBSSourceFilterVisibility) {
1414
var obs = new OBSWebSocket();
1515
obs.connect(address, password).then(async () => {
16+
obs.getVersion().then(data => {
17+
console.error(`Kruiz Control connected to the OBS Websocket v${data.obsWebSocketVersion}`);
18+
});
1619
obsHandler.setCurrentScene(await obs.getCurrentScene());
1720
obsHandler.success();
1821
}).catch(err => { // Promise convention dictates you have a catch on every chain.
@@ -473,6 +476,25 @@ function connectOBSWebsocket(address, password, obsHandler, onSwitchScenes, onTr
473476
});
474477
};
475478

479+
obs.setSceneItemRotation = async function(scene, source, rotation) {
480+
await this.call('SetSceneItemTransform', {
481+
'sceneName': scene,
482+
'sceneItemId': await this.getSceneItemId(scene, source),
483+
'sceneItemTransform': {
484+
'rotation': rotation
485+
}
486+
}).catch(async err => {
487+
if (err.code === 600) {
488+
var group = await this.getSourceGroupName(scene, source);
489+
if (group) {
490+
await this.setSceneItemRotation(group, source, rotation);
491+
return;
492+
}
493+
}
494+
console.error(JSON.stringify(err));
495+
});
496+
};
497+
476498
obs.getCurrentTransition = async function() {
477499
return await this.call('GetCurrentSceneTransition')
478500
.then(data => {
@@ -490,5 +512,13 @@ function connectOBSWebsocket(address, password, obsHandler, onSwitchScenes, onTr
490512
});
491513
};
492514

515+
obs.getStats = async function() {
516+
return await this.call('GetStats').then(data => {
517+
return data;
518+
}).catch(err => {
519+
console.error(JSON.stringify(err));
520+
});
521+
}
522+
493523
return obs;
494524
}

js/obs/obsHandler.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,15 @@ class OBSHandler extends Handler {
331331
var currentScene = await this.obs.getCurrentScene();
332332
return {current_scene: currentScene};
333333
break;
334+
case 'flip':
335+
var { scene, source, direction } = Parser.getInputs(triggerData, ['action', 'scene', 'source', 'direction']);
336+
var { sceneItemTransform } = await this.obs.getSceneItemTransform(scene, source);
337+
if (direction.toLowerCase() === 'y') {
338+
await this.obs.setSceneItemSize(scene, source, sceneItemTransform.scaleX, -1 * sceneItemTransform.scaleY);
339+
} else {
340+
await this.obs.setSceneItemSize(scene, source, -1 * sceneItemTransform.scaleX, sceneItemTransform.scaleY);
341+
}
342+
break;
334343
case 'isscenesourcevisible':
335344
var { scene, source } = Parser.getInputs(triggerData, ['action', 'scene', 'source']);
336345
if (scene === '{current}') {
@@ -409,6 +418,14 @@ class OBSHandler extends Handler {
409418
var source = triggerData.slice(2).join(' ');
410419
await this.obs.refreshBrowser(source);
411420
break;
421+
case 'rotate':
422+
var { scene, source, degree } = Parser.getInputs(triggerData, ['action', 'scene', 'source', 'degree']);
423+
degree = parseFloat(degree);
424+
degree = degree % 360;
425+
if (!isNaN(degree)) {
426+
await this.obs.setSceneItemRotation(scene, source, degree);
427+
}
428+
break;
412429
case 'savereplaybuffer':
413430
await this.obs.saveReplayBuffer();
414431
break;
@@ -484,6 +501,19 @@ class OBSHandler extends Handler {
484501
case 'startstream':
485502
await this.obs.startStream();
486503
break;
504+
case 'stats':
505+
var data = await this.obs.getStats();
506+
return {
507+
cpu: Math.round((data.cpuUsage + Number.EPSILON) * 100) / 100,
508+
memory: Math.round((data.memoryUsage + Number.EPSILON) * 100) / 100,
509+
disk_space: Math.round((data.availableDiskSpace + Number.EPSILON) * 100) / 100,
510+
fps: Math.round(data.activeFps),
511+
average_render_time: Math.round((data.averageFrameRenderTime + Number.EPSILON) * 100) / 100,
512+
render_skipped_frames: data.renderSkippedFrames,
513+
output_skipped_frames: data.outputSkippedFrames,
514+
data: data
515+
}
516+
break;
487517
case 'stopreplaybuffer':
488518
await this.obs.stopReplayBuffer();
489519
break;

js/tts/ttsHandler.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,38 @@ class TTSHandler extends Handler {
2828
this.updateVoices(voices);
2929
listParser.createList(name, voices.map(voice => voice.name));
3030
} else {
31-
var { voice, volume, wait, message } = Parser.getInputs(triggerData, ['voice', 'volume', 'wait', 'message']);
31+
var inputs = Parser.getInputs(triggerData, ['voice', 'volume', 'pitch', 'rate', 'wait', 'message']);
32+
if (Object.keys(inputs).length === 0) {
33+
inputs = Parser.getInputs(triggerData, ['voice', 'volume', 'wait', 'message']);
34+
}
35+
var { voice, volume, pitch, rate, wait, message } = inputs;
36+
3237
volume = parseInt(volume);
3338
if (isNaN(volume)) {
3439
volume = 0.8;
3540
} else {
3641
volume = volume / 100;
3742
}
43+
44+
pitch = parseInt(pitch);
45+
if (isNaN(pitch)) {
46+
pitch = 1;
47+
} else {
48+
pitch = pitch / 100 * 2;
49+
}
50+
51+
rate = parseInt(rate);
52+
if (isNaN(rate)) {
53+
rate = 1;
54+
} else {
55+
rate = (rate / 100 * 9.9) + 0.1;
56+
}
57+
3858
var msg = new SpeechSynthesisUtterance();
3959
msg.text = message;
4060
msg.volume = volume;
61+
msg.pitch = pitch;
62+
msg.rate = rate;
4163

4264
// Load voices if not loaded yet
4365
if (Object.keys(this.voices).length === 0) {

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.6.1
1+
v1.6.2

0 commit comments

Comments
 (0)