Skip to content

Commit

Permalink
Merge pull request #57 from Kruiser8/develop
Browse files Browse the repository at this point in the history
Update for v1.6.2
  • Loading branch information
Kruiser8 authored Nov 14, 2022
2 parents 8ef3c20 + d52278b commit 56439a4
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 10 deletions.
84 changes: 78 additions & 6 deletions js/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Each handler provides its own triggers and actions that can be used in a trigger
* [Actions](#obs-actions)
+ [OBS AddSceneItem](#obs-addsceneitem)
+ [OBS CurrentScene](#obs-currentscene)
+ [OBS Flip](#obs-flip)
+ [OBS IsSceneSourceVisible](#obs-isscenesourcevisible)
+ [OBS IsSourceActive](#obs-issourceactive)
+ [OBS Media Duration](#obs-media-duration)
Expand All @@ -148,6 +149,7 @@ Each handler provides its own triggers and actions that can be used in a trigger
+ [OBS Mute](#obs-mute)
+ [OBS Position](#obs-position)
+ [OBS Refresh](#obs-refresh)
+ [OBS Rotate](#obs-rotate)
+ [OBS SaveReplayBuffer](#obs-savereplaybuffer)
+ [OBS Scene](#obs-scene)
+ [OBS SceneSource](#obs-scenesource)
Expand All @@ -159,6 +161,7 @@ Each handler provides its own triggers and actions that can be used in a trigger
+ [OBS Source URL](#obs-source-url)
+ [OBS StartReplayBuffer](#obs-startreplaybuffer)
+ [OBS StartStream](#obs-startstream)
+ [OBS Stats](#obs-stats)
+ [OBS StopReplayBuffer](#obs-stopreplaybuffer)
+ [OBS StopStream](#obs-stopstream)
+ [OBS TakeSourceScreenshot](#obs-takesourcescreenshot)
Expand Down Expand Up @@ -1432,9 +1435,11 @@ Use this to determine all global variables in Kruiz Control.
**Format** | `Globals <name>`
**Example** | `Globals MyGlobals`

##### Example Usage

<table>
<tr>
<td>Example Usage: Sends all global variable names chat</td>
<td>Sends all global variable names chat</td>
</tr>
<tr>
<td>
Expand All @@ -1454,7 +1459,7 @@ Chat Send {value}

<table>
<tr>
<td>Example Usage: Sends all global variable names and values to an example API</td>
<td>Sends all global variable names and values to an example API</td>
</tr>
<tr>
<td>
Expand Down Expand Up @@ -1682,6 +1687,15 @@ Enables the ability to interact with and respond to OBS.

***

#### OBS Flip
| | |
------------ | -------------
**Info** | Used to flip a source in OBS.
**Format** | `OBS Flip <scene> <source> <x/y>`
**Example** | `OBS Flip Webcam Camera x`

***

#### OBS IsSceneSourceVisible
| | |
------------ | -------------
Expand Down Expand Up @@ -1811,6 +1825,17 @@ Enables the ability to interact with and respond to OBS.

***

#### OBS Rotate
| | |
------------ | -------------
**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.
**Format** | `SLOBS Rotate <scene> <source> <degree>`
**Example** | `SLOBS Rotate Webcam Camera 90`

_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`._

***

#### OBS Scene
| | |
------------ | -------------
Expand Down Expand Up @@ -1923,6 +1948,48 @@ _Note: The browser source does not need to be in current/active scene for this t
**Format** | `OBS StartStream`
**Example** | `OBS StartStream`

***

#### OBS Stats
| | |
------------ | -------------
**Info** | Used to retrieve OBS statistics.
**Format** | `OBS Stats`
**Example** | `OBS Stats`

##### Parameters
| | |
------------ | -------------
**cpu** | Percent CPU in use by OBS.
**memory** | Amount of memory in MB currently being used by OBS.
**disk_space** | Available disk space on the device being used for recording storage.
**fps** | Current FPS being rendered.
**average_render_time** | Average time in milliseconds that OBS is taking to render a frame.
**render_skipped_frames** | Number of rendered frames skipped by OBS (render frames are frames produced even when not recording or streaming).
**output_skipped_frames** | Number of output frames skipped by OBS (the frames being recorded or streamed).
**data** | The entire [OBS Websocket GetStats output](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#getstats).

##### Example Usage

<table>
<tr>
<td>Sends OBS statistics to chat</td>
</tr>
<tr>
<td>

```m
OnInit
OBS Stats
Error "OBS is using {cpu}% CPU and {memory}MB RAM."
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."
```

</td>
</tr>
</table>


***

#### OBS StopReplayBuffer
Expand Down Expand Up @@ -2751,9 +2818,12 @@ None at the moment.
#### TTS
| | |
------------ | -------------
**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.
**Format** | `TTS <voice> <volume> <wait/nowait> <message>`
**Example** | `TTS "Microsoft David - English (United States)" 70 wait "Hey there!"`
**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.
**Format** | `TTS <voice> <volume> <pitch> <rate> <wait/nowait> <message>`
**Example** | `TTS "Microsoft David - English (United States)" 70 50 20 wait "Hey there!"`
**Example w/ default pitch & rate** | `TTS "Microsoft David - English (United States)" 70 - - wait "Hey there!"`

_Note: For backwards compatibility, the `<pitch>` and `<rate>` inputs are optional, but they are both required if one of them is provided._

***

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

##### Example Usage

<table>
<tr>
<td>Example Usage: Sends all voice options to chat</td>
<td>Sends all voice options to chat</td>
</tr>
<tr>
<td>
Expand Down
10 changes: 8 additions & 2 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Do stuff if the document is fully loaded
$(document).ready(async function() {
var version = await readFile("version.txt");
console.error(`Kruiz Control ${version.trim()} Initialized`);
var data = await readFile("triggers.txt");
await readTriggerFile(data);
});
Expand All @@ -25,8 +27,12 @@ async function readFileTriggers(data) {
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
if (!line.startsWith('#') && line.trim().length > 0) {
var input = await readFile('triggers/' + line);
controller.parseInput(input, true);
try {
var input = await readFile('triggers/' + line);
controller.parseInput(input, true);
} catch (error) {
console.error(`Check that the ${line} file exists in the triggers folder`);
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions js/obs/obs-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
function connectOBSWebsocket(address, password, obsHandler, onSwitchScenes, onTransitionBegin, onStreamStateChange, onCustomMessage, onOBSSourceVisibility, onOBSSourceFilterVisibility) {
var obs = new OBSWebSocket();
obs.connect(address, password).then(async () => {
obs.getVersion().then(data => {
console.error(`Kruiz Control connected to the OBS Websocket v${data.obsWebSocketVersion}`);
});
obsHandler.setCurrentScene(await obs.getCurrentScene());
obsHandler.success();
}).catch(err => { // Promise convention dictates you have a catch on every chain.
Expand Down Expand Up @@ -473,6 +476,25 @@ function connectOBSWebsocket(address, password, obsHandler, onSwitchScenes, onTr
});
};

obs.setSceneItemRotation = async function(scene, source, rotation) {
await this.call('SetSceneItemTransform', {
'sceneName': scene,
'sceneItemId': await this.getSceneItemId(scene, source),
'sceneItemTransform': {
'rotation': rotation
}
}).catch(async err => {
if (err.code === 600) {
var group = await this.getSourceGroupName(scene, source);
if (group) {
await this.setSceneItemRotation(group, source, rotation);
return;
}
}
console.error(JSON.stringify(err));
});
};

obs.getCurrentTransition = async function() {
return await this.call('GetCurrentSceneTransition')
.then(data => {
Expand All @@ -490,5 +512,13 @@ function connectOBSWebsocket(address, password, obsHandler, onSwitchScenes, onTr
});
};

obs.getStats = async function() {
return await this.call('GetStats').then(data => {
return data;
}).catch(err => {
console.error(JSON.stringify(err));
});
}

return obs;
}
30 changes: 30 additions & 0 deletions js/obs/obsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ class OBSHandler extends Handler {
var currentScene = await this.obs.getCurrentScene();
return {current_scene: currentScene};
break;
case 'flip':
var { scene, source, direction } = Parser.getInputs(triggerData, ['action', 'scene', 'source', 'direction']);
var { sceneItemTransform } = await this.obs.getSceneItemTransform(scene, source);
if (direction.toLowerCase() === 'y') {
await this.obs.setSceneItemSize(scene, source, sceneItemTransform.scaleX, -1 * sceneItemTransform.scaleY);
} else {
await this.obs.setSceneItemSize(scene, source, -1 * sceneItemTransform.scaleX, sceneItemTransform.scaleY);
}
break;
case 'isscenesourcevisible':
var { scene, source } = Parser.getInputs(triggerData, ['action', 'scene', 'source']);
if (scene === '{current}') {
Expand Down Expand Up @@ -409,6 +418,14 @@ class OBSHandler extends Handler {
var source = triggerData.slice(2).join(' ');
await this.obs.refreshBrowser(source);
break;
case 'rotate':
var { scene, source, degree } = Parser.getInputs(triggerData, ['action', 'scene', 'source', 'degree']);
degree = parseFloat(degree);
degree = degree % 360;
if (!isNaN(degree)) {
await this.obs.setSceneItemRotation(scene, source, degree);
}
break;
case 'savereplaybuffer':
await this.obs.saveReplayBuffer();
break;
Expand Down Expand Up @@ -484,6 +501,19 @@ class OBSHandler extends Handler {
case 'startstream':
await this.obs.startStream();
break;
case 'stats':
var data = await this.obs.getStats();
return {
cpu: Math.round((data.cpuUsage + Number.EPSILON) * 100) / 100,
memory: Math.round((data.memoryUsage + Number.EPSILON) * 100) / 100,
disk_space: Math.round((data.availableDiskSpace + Number.EPSILON) * 100) / 100,
fps: Math.round(data.activeFps),
average_render_time: Math.round((data.averageFrameRenderTime + Number.EPSILON) * 100) / 100,
render_skipped_frames: data.renderSkippedFrames,
output_skipped_frames: data.outputSkippedFrames,
data: data
}
break;
case 'stopreplaybuffer':
await this.obs.stopReplayBuffer();
break;
Expand Down
24 changes: 23 additions & 1 deletion js/tts/ttsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,38 @@ class TTSHandler extends Handler {
this.updateVoices(voices);
listParser.createList(name, voices.map(voice => voice.name));
} else {
var { voice, volume, wait, message } = Parser.getInputs(triggerData, ['voice', 'volume', 'wait', 'message']);
var inputs = Parser.getInputs(triggerData, ['voice', 'volume', 'pitch', 'rate', 'wait', 'message']);
if (Object.keys(inputs).length === 0) {
inputs = Parser.getInputs(triggerData, ['voice', 'volume', 'wait', 'message']);
}
var { voice, volume, pitch, rate, wait, message } = inputs;

volume = parseInt(volume);
if (isNaN(volume)) {
volume = 0.8;
} else {
volume = volume / 100;
}

pitch = parseInt(pitch);
if (isNaN(pitch)) {
pitch = 1;
} else {
pitch = pitch / 100 * 2;
}

rate = parseInt(rate);
if (isNaN(rate)) {
rate = 1;
} else {
rate = (rate / 100 * 9.9) + 0.1;
}

var msg = new SpeechSynthesisUtterance();
msg.text = message;
msg.volume = volume;
msg.pitch = pitch;
msg.rate = rate;

// Load voices if not loaded yet
if (Object.keys(this.voices).length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.6.1
v1.6.2

0 comments on commit 56439a4

Please sign in to comment.