Skip to content

Commit

Permalink
Changed plugin output name
Browse files Browse the repository at this point in the history
* Should avoid conflict with the original plugin. oops.
* Bumped version to 0.2.0.
* Cleaned up integration enablement instructions.
* Finer steps allowed on voice generator effects (0.1 -> 0.05)
* Better logging for null or error responses from gcloud.tts.synth
  • Loading branch information
phroggster committed Jun 1, 2024
1 parent 8ae67e7 commit b94b88c
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 49 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "google-cloud-tts",
"scriptOutputName": "googleCloudTts",
"version": "0.1.2",
"name": "google-cloud-tts-revised",
"scriptOutputName": "googleCloudTtsRevised",
"version": "0.2.0",
"description": "Adds Google Cloud Services integration, and a higher-quality TTS effect utilizing it to Firebot",
"main": "",
"scripts": {
Expand Down
70 changes: 40 additions & 30 deletions src/google-cloud-service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { IntegrationWithUnknowns, ScriptModules } from "@crowbartools/firebot-custom-scripts-types";
import axios from "axios";
import { AxiosResponse } from "axios";

import { logger } from "./logger";
import { EffectParams, GoogleCloud, VoiceInfo, VoiceSelectionParams } from "./types";

type SynthesizeTextResponse = {
audioContent: string;
}

class GoogleCloudService implements GoogleCloud {
constructor(
private readonly frontendCommunicator: ScriptModules["frontendCommunicator"],
Expand Down Expand Up @@ -88,11 +93,6 @@ class GoogleCloudService implements GoogleCloud {
}

async synthesizeSsml(ssmlToSynthesize: string, voiceParams: VoiceSelectionParams, effectParams?: EffectParams): Promise<string | undefined> {
type SynthesizeTextResponse = {
audioContent: string;
}

logger.debug(`google-cloud-service.synthesizeSsml: received request: ssmlToSynth: ${ssmlToSynthesize}, voiceParams: ${voiceParams}, effectParams: ${effectParams}`);
const gcpIntegration = this.integrationManager.getIntegrationById("google-cloud-key");
const apiKey = this._getApiKey(gcpIntegration);
if (apiKey === null) {
Expand All @@ -104,36 +104,40 @@ class GoogleCloudService implements GoogleCloud {
effectParams.effects = [];
}

logger.debug(`google-cloud-service.synthesizeSsml: received synthesizeSsml request for "${ssmlToSynthesize}"`);
const url = `https://texttospeech.googleapis.com/v1/text:synthesize?key=${apiKey}`;
const response = await axios.post<SynthesizeTextResponse>(url, {
input: {
ssml: ssmlToSynthesize
},
voice: {
languageCode: voiceParams.language,
name: voiceParams.name
},
audioConfig: {
audioEncoding: "MP3",
pitch: effectParams?.pitch ?? 0.0,
speakingRate: effectParams?.rate ?? 1.0,
volumeGainDb: effectParams?.volume ?? 0.0,
effectsProfileId: effectParams?.effects ?? []
let response: AxiosResponse<SynthesizeTextResponse>;
try {
response = await axios.post<SynthesizeTextResponse>(url, {
input: {
ssml: ssmlToSynthesize
},
voice: {
languageCode: voiceParams.language,
name: voiceParams.name
},
audioConfig: {
audioEncoding: "MP3",
pitch: effectParams?.pitch ?? 0.0,
speakingRate: effectParams?.rate ?? 1.0,
volumeGainDb: effectParams?.volume ?? 0.0,
effectsProfileId: effectParams?.effects ?? []
}
});

if (response.status < 200 || response.status >= 300 || !response.data?.audioContent) {
const dataText = response.data?.audioContent ? 'data' : 'no data';
logger.warn(`google-cloud-service.synthesizeSsml: received ${dataText}, code ${response.status}: ${response.statusText}`, response);
}
}).catch(err => {
logger.error("google-cloud-service.synthesizeSsml: Failed to request Google Cloud text-to-speech ssml synthesis", err);
throw err;
});
}
catch (err) {
logger.error("google-cloud-service.synthesizeSsml: error synthesizing ssml", err);
}

return response?.data?.audioContent;
}

async synthesizeText(textToSynthesize: string, voiceParams: VoiceSelectionParams, effectParams?: EffectParams): Promise<string | undefined> {
type SynthesizeTextResponse = {
audioContent: string;
}

logger.debug("google-cloud-service.synthesizeText: received synthesizeText request...");
const gcpIntegration = this.integrationManager.getIntegrationById("google-cloud-key");
const apiKey = this._getApiKey(gcpIntegration);
if (apiKey == null || apiKey.length < 20) {
Expand All @@ -146,8 +150,9 @@ class GoogleCloudService implements GoogleCloud {
effectParams.effects = [];
}

logger.debug(`google-cloud-service.synthesizeText: received synthesizeText request for "${textToSynthesize}"`);
const url = `https://texttospeech.googleapis.com/v1/text:synthesize?key=${apiKey}`;
let response = undefined;
let response: AxiosResponse<SynthesizeTextResponse>;
try {
response = await axios.post<SynthesizeTextResponse>(url, {
input: {
Expand All @@ -165,9 +170,14 @@ class GoogleCloudService implements GoogleCloud {
effectsProfileId: effectParams?.effects ?? []
}
});

if (response.status < 200 || response.status >= 300 || !response.data?.audioContent) {
const dataText = response.data?.audioContent ? 'data' : 'no data';
logger.warn(`google-cloud-service.synthesizeText: received ${dataText}, code ${response.status}: ${response.statusText}`, response);
}
}
catch (err) {
logger.error("google-cloud-service.synthesizeText: unable to sythesize text", err);
logger.error("google-cloud-service.synthesizeText: error synthesizing text", err);
return;
}

Expand Down
18 changes: 10 additions & 8 deletions src/google-integration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Integration, IntegrationController, IntegrationData, IntegrationEvents, ScriptModules } from "@crowbartools/firebot-custom-scripts-types";
import { Integration, IntegrationController, IntegrationDefinition, IntegrationData, IntegrationEvents, ScriptModules } from "@crowbartools/firebot-custom-scripts-types";
import { FirebotParams } from "@crowbartools/firebot-custom-scripts-types/types/modules/firebot-parameters";
import { TypedEmitter } from "tiny-typed-emitter";

import { consts } from "./consts";
Expand Down Expand Up @@ -45,20 +46,21 @@ export type IntegrationSettings = {
};
*/

const integrationDefinition = {
const integrationDefinition: IntegrationDefinition<FirebotParams> = {
id: consts.INTEGRATION_ID,
name: "Google Cloud Platform",
description: "Google Cloud Platform integration, for use with the Text to Speech API",
connectionToggle: true,
linkType: "id",
idDetails: {
steps:
`1. Navigate to the Google Cloud Platform Credentials page for your project (https://console.cloud.google.com/apis/credentials).
2. Either create a new API Key by clicking "+ CREATE CREDENTIALS" at the top, or click "SHOW KEY" on a pre-existing API Key.
3. Paste your API Key below.`
steps: `
1. Visit the [Google Cloud Platform Credentials](https://console.cloud.google.com/apis/credentials) page for your project.
2. Either:
- Click <ins>SHOW KEY</ins> on a pre-existing API Key, ***OR*** . . .
- Click <ins>+ CREATE CREDENTIALS</ins> at the top to create a new key.
3. Paste the API Key below.`
},
settingCategories: null
};

class IntegrationEventEmitter extends TypedEmitter<IntegrationEvents> { };
Expand Down
6 changes: 3 additions & 3 deletions src/google-tts-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,23 @@ export function initGoogleTtsEffectType(
<h4>Pitch</h4>
<div class="volume-slider-wrapper">
<i class="fal fa-chevron-double-down"></i>
<rzslider rz-slider-model="effect.effectPitch" rz-slider-options="{floor: -20.0, ceil: 20.0, precision: 1, step: 0.1}"></rzslider>
<rzslider rz-slider-model="effect.effectPitch" rz-slider-options="{floor: -20.0, ceil: 20.0, precision: 1, step: 0.05}"></rzslider>
<i class="fal fa-chevron-double-up"></i>
</div>
</div>
<div>
<h4>Rate</h4>
<div class="volume-slider-wrapper">
<i class="fal fa-backward"></i>
<rzslider rz-slider-model="effect.effectRate" rz-slider-options="{floor: -0.25, ceil: 4, precision: 2, step: 0.1}"></rzslider>
<rzslider rz-slider-model="effect.effectRate" rz-slider-options="{floor: -0.25, ceil: 4, precision: 2, step: 0.05}"></rzslider>
<i class="fal fa-forward"></i>
</div>
</div>
<div>
<h4>Volume</h4>
<div class="volume-slider-wrapper">
<i class="fal fa-volume-down volume-low"></i>
<rzslider rz-slider-model="effect.effectVolume" rz-slider-options="{floor: -96, ceil: 16, precision: 1, step: 0.1}"></rzslider>
<rzslider rz-slider-model="effect.effectVolume" rz-slider-options="{floor: -96, ceil: 16, precision: 1, step: 0.05}"></rzslider>
<i class="fal fa-volume-up volume-high"></i>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const script: Firebot.CustomScript = {
name: "Google Cloud TTS Effect",
description: "Adds the Google Cloud TTS effect",
author: "phroggie, heyaapl",
version: "0.2",
version: "0.2.0",
firebotVersion: "5",
startupOnly: true,
website: "https://github.com/phroggster/firebot-google-cloud-tts"
Expand Down

0 comments on commit b94b88c

Please sign in to comment.