node-megabalabolka 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.MD +100 -0
  2. package/index.js +71 -0
  3. package/package.json +23 -0
package/README.MD ADDED
@@ -0,0 +1,100 @@
1
+ # Mega Balabolka! The node.js Library
2
+
3
+ This package (or library) allows you to communicate with Balabolka's Console Application (balcon) for use in your nodejs application.
4
+
5
+ ## Installation
6
+
7
+ Via npm:
8
+ ```sh
9
+ $ npm install node-megabalabolka
10
+ ```
11
+
12
+ ## Prerequisites
13
+
14
+ In order to use this library, you must have balcon added to your PATH.<br />
15
+ You can download balcon by clicking [here](http://www.cross-plus-a.com/balcon.zip).
16
+
17
+ ## Usage
18
+
19
+ Usage for basic generation, output will be in the WAV format.
20
+
21
+ ```js
22
+ const balcon = require('node-megabalabolka')
23
+
24
+ options = {
25
+ list: false,
26
+ warnings: true,
27
+ writeToBuffer: false,
28
+ ignoreLength: false,
29
+ raw: false,
30
+ encoding: false,
31
+ pitch: 0,
32
+ speed: 0,
33
+ voice: "Microsoft David Desktop",
34
+ volume: "100",
35
+ text: "This is an example of mega balabolka generation.",
36
+ file: `${Math.round(Date.now() / 1000)}.wav`
37
+ }
38
+ balcon.generate(options).then(a => {
39
+ if (options.writeToBuffer == true) {
40
+ console.log("BufferLength:" + a.length)
41
+ }
42
+ }).catch(error => {
43
+ console.error(error)
44
+ return false;
45
+ })
46
+ ```
47
+
48
+ ## Inputs
49
+ All inputs are handled by passing them through an Object. <br />
50
+ Those inputs are as followed:
51
+
52
+ ### list:
53
+ Assignments: Can be set to true or false.<br />
54
+ Usage: will ignore all other commands and be used to list voices
55
+
56
+ ### warnings:
57
+ Assignments: Can be set to true or false.<br />
58
+ Usage: will log all warning sent out
59
+
60
+ ### writetoBuffer:
61
+ Assignments: Can be set to true or false.<br />
62
+ Usage: Passes the command -o and will write all sounddata to STDOUT to be used later in a buffer.
63
+
64
+ ### ignoreLength:
65
+ Assignments: Can be set to true or false.<br />
66
+ Usage: Passes along an -il command to balcon which [omits the length of data in the WAV header](http://www.cross-plus-a.com/bconsole.htm).
67
+
68
+ ### raw:
69
+ Assignments: Can be set to true or false.<br />
70
+ Usage: Output will contain raw PCM although this might only work in [SAPI 5](http://www.cross-plus-a.com/bconsole.htm)
71
+
72
+ ### encoding:
73
+ Assignments: Can be set to utf8, ansi, or unicode.<br />
74
+ Usage: Output will be encoded to use either three encoding formats.
75
+
76
+ ### pitch:
77
+ Assignments: Interger.<br />
78
+ Usage: Sets the pitch of the voice.
79
+
80
+ ### speed:
81
+ Assignments: Interger.<br />
82
+ Usage: Sets the speed of the voice.
83
+
84
+ ### volume:
85
+ Assignments: Interger.<br />
86
+ Usage: Sets the volume of the voice.
87
+
88
+ ### text:
89
+ Assignments: String.<br />
90
+ Usage: Sets the text that will be generated.
91
+
92
+ ### file:
93
+ Assignments: String.<br />
94
+ Usage: Sets the filename and/or path that will be used to write the generation to disc.
95
+ Will be ignored if `writeToBuffer` is true.
96
+
97
+ ### voice:
98
+ Assignments: Text.<br />
99
+ Usage: Sets the voice being used the generate the text.<br />
100
+ you can find out what voices you have installed on your computer by running `balcon -l`
package/index.js ADDED
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Written By MegaT
3
+ * 2022
4
+ */
5
+
6
+ const { exec } = require('child_process');
7
+
8
+ function generate(options) {
9
+ return new Promise(function (resolve, reject) {
10
+ var prompt;
11
+ var list = false;
12
+ if (options.list == true) {
13
+ prompt = `balcon -l`
14
+ list = true;
15
+ }
16
+ else {
17
+ prompt = `balcon`;
18
+ if (options.voice) {
19
+ prompt += ` -n ${options.voice} `
20
+ }
21
+ if (options.text) {
22
+ prompt += `-t "${options.text.replace(/["]+/g, '')}" `
23
+ }
24
+ if (options.speed) {
25
+ prompt += `-s "${options.speed}" `
26
+ }
27
+ if (options.pitch) {
28
+ prompt += `-p "${options.pitch}" `
29
+ }
30
+ if (options.volume) {
31
+ prompt += `-v "${options.volume}" `
32
+ }
33
+ if (!options.writeToBuffer) {
34
+ if (options.file) {
35
+ prompt += `-w "${options.file}" `
36
+ }
37
+ } else {
38
+ prompt += `-o`
39
+ if (options.ignoreLength)
40
+ prompt += ` -il`
41
+ if (options.encoding) {
42
+ prompt += ` --encoding ${options.encoding}`
43
+ }
44
+ }
45
+ if (options.raw) {
46
+ prompt += ` --raw`
47
+ }
48
+ }
49
+ const ls = exec(prompt, function (error, stdout, stderr) {
50
+ if (error) {
51
+ console.log('STDERR: ' + stderr);
52
+ console.error(error.stack);
53
+ console.error('Error code: ' + error.code);
54
+ console.error('Signal received: ' + error.signal);
55
+ reject(stderr);
56
+ }
57
+ if (options.warnings) {
58
+ if (stderr)
59
+ console.log('Warning: ' + stderr);
60
+ }
61
+ if (list = true) {
62
+ resolve(stdout);
63
+ }
64
+ });
65
+
66
+ ls.on('exit', function (code) {
67
+ })
68
+ })
69
+ }
70
+
71
+ module.exports = { generate };
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "node-megabalabolka",
3
+ "version": "1.0.0",
4
+ "description": "This package communicates with balcon and gives the information back to nodejs",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "start": "node index.js"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/MegaTeam89/node-megabalabolka.git"
12
+ },
13
+ "keywords": [
14
+ "balabolka",
15
+ "balcon"
16
+ ],
17
+ "author": "MegaT",
18
+ "license": "GPL-3.0",
19
+ "bugs": {
20
+ "url": "https://github.com/MegaTeam89/node-megabalabolka/issues"
21
+ },
22
+ "homepage": "https://github.com/MegaTeam89/node-megabalabolka#readme"
23
+ }