Skip to content
This repository was archived by the owner on Nov 27, 2025. It is now read-only.
Open
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
28 changes: 24 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ async function initialize(): Promise<void> {
}
}

function validateEnvironment(environment: string | null | undefined): boolean {
if (!environment && !config.environment) {
return true;
}
return environment === config.environment;
}

function getParameters(params: SpeechParams): InstantiatedSpeechParams {
if (params.lang) {
params.language = params.lang;
Expand Down Expand Up @@ -233,12 +240,19 @@ function exceptionHandler(err: Error): void {
}

if (io.rabbit) {
io.rabbit.onTopic('speaker.command.cache.clear', () => {
io.rabbit.onTopic('speaker.command.cache.clear', (response) => {
const msg = (response.content as { environment?: string });
if (!validateEnvironment(msg.environment)) {
return;
}
clearCache();
});

io.rabbit.onTopic('speaker.command.default.language', (response) => {
const msg = (response.content as {language: string});
const msg = (response.content as { environment?: string; language: string });
if (!validateEnvironment(msg.environment)) {
return;
}
if (languages[msg.language]) {
config.language = msg.language;
logger.info(`Default language set to ${config.language}`);
Expand All @@ -249,7 +263,10 @@ if (io.rabbit) {
});

io.rabbit.onTopic('speaker.command.default.voice', (response) => {
const msg = (response.content as {language: string; voice: string});
const msg = (response.content as { environment?: string; language: string; voice: string });
if (!validateEnvironment(msg.environment)) {
return;
}
if (languages[msg.language]) {
if (languages[msg.language].includes(msg.voice)) {
config.voices[msg.language] = msg.voice;
Expand All @@ -265,7 +282,10 @@ if (io.rabbit) {
});

io.rabbit.onTopic('speaker.command.volume.change', (response) => {
const msg = (response.content as {change?: number; volume?: number});
const msg = (response.content as { environment?: string; change?: number; volume?: number });
if (!validateEnvironment(msg.environment)) {
return;
}
if (msg.change) {
config.volume = config.volume + msg.change / 100;
}
Expand Down