Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10,334 changes: 3,575 additions & 6,759 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@
"author": "ebiggz",
"license": "GNU3",
"devDependencies": {
"@types/node": "^14.14.6",
"@crowbartools/firebot-custom-scripts-types": "^5.60.1",
"@types/node": "^18.18.2",
"@types/uuid": "^8.3.0",
"firebot-custom-scripts-types": "https://github.com/crowbartools/firebot-custom-scripts-types/tarball/8dbd4a5b67e01989568201351c24ccecb2ab055a",
"jest": "^26.6.3",
"terser-webpack-plugin": "^4.2.3",
"ts-jest": "^26.4.4",
"ts-loader": "^8.0.7",
"typescript": "^4.0.5",
"webpack": "^4.44.2",
"webpack-cli": "^4.1.0"
"jest": "29.7",
"terser-webpack-plugin": "^5.3.10",
"ts-jest": "^29.1.1",
"ts-loader": "^9.5.1",
"typescript": "^5.3.3",
"webpack": "5.89",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"axios": "^0.21.1",
"axios": "^1.6.8",
"uuid": "^8.3.2"
},
"volta": {
"node": "18.18.2",
"npm": "10.2.4"
}
}
5 changes: 5 additions & 0 deletions scripts/copy-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const getFirebotScriptsFolderPath = () => {
process.env.HOME,
"/Library/Application Support"
);
} else if (process.platform === "linux") {
appDataFolderPath = path.join(
process.env.HOME,
"/.config"
);
} else {
throw new Error("Unsupported OS!");
}
Expand Down
1 change: 1 addition & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare const SCRIPTS_DIR: string;
15 changes: 9 additions & 6 deletions src/google-tts-effect.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import axios from "axios";
import { Firebot, ScriptModules } from "firebot-custom-scripts-types";
import { Firebot, ScriptModules } from "@crowbartools/firebot-custom-scripts-types";
import { v4 as uuid } from "uuid";
import { getTTSAudioContent } from "./google-api";
import { logger } from "./logger";
import { wait } from "./utils";
import {tmpDir, wait} from "./utils";
import { EffectModel } from "./types";

export function buildGoogleTtsEffectType(
Expand Down Expand Up @@ -121,10 +120,14 @@ export function buildGoogleTtsEffectType(
return true;
}

const filePath = path.join(process.cwd(), `tts${uuid()}.mp3`);
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir);
}

const filePath = path.join(tmpDir, `tts${uuid()}.mp3`);

// save audio content to file
await fs.writeFile(filePath, Buffer.from(audioContent, "base64"));
fs.writeFileSync(filePath, Buffer.from(audioContent, "base64"));

// get the duration of this tts sound duration
const soundDuration = await frontendCommunicator.fireEventAsync<number>(
Expand All @@ -147,7 +150,7 @@ export function buildGoogleTtsEffectType(
await wait((soundDuration + 1.5) * 1000);

// remove the audio file
await fs.unlink(filePath);
fs.unlinkSync(filePath);
} catch (error) {
logger.error("Google Cloud TTS Effect failed", error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ScriptModules } from "firebot-custom-scripts-types";
import { ScriptModules } from "@crowbartools/firebot-custom-scripts-types";
export let logger: ScriptModules["logger"] = {
debug: () => {},
info: () => {},
Expand Down
8 changes: 5 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Firebot } from "firebot-custom-scripts-types";
import { Firebot } from "@crowbartools/firebot-custom-scripts-types";
import { buildGoogleTtsEffectType } from "./google-tts-effect";
import { initLogger } from "./logger";
import { setTmpDir } from "./utils";

interface Params {
googleCloudAPIKey: string
Expand Down Expand Up @@ -29,8 +30,9 @@ const script: Firebot.CustomScript<Params> = {
},
run: (runRequest) => {
const { effectManager, frontendCommunicator, logger } = runRequest.modules;
const fs = (runRequest.modules as any).fs;
const path = (runRequest.modules as any).path;
const fs = runRequest.modules.fs;
const path = runRequest.modules.path;
setTmpDir(path.join(SCRIPTS_DIR, '..', '..', '..', '..', 'tmp', 'google-tts'));
initLogger(logger);
effectManager.registerEffect(
buildGoogleTtsEffectType(frontendCommunicator, fs, path, runRequest.parameters.googleCloudAPIKey)
Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export const wait = (ms: number) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};

export let tmpDir: string;

export function setTmpDir(dir: string) {
tmpDir = dir;
}