Skip to content

Commit

Permalink
Merge pull request #347 from MikelCalvo/feature/tss_text_optional
Browse files Browse the repository at this point in the history
Add control on returning TTS response as text message
  • Loading branch information
steve-hb authored Aug 1, 2024
2 parents e196fd3 + ada7b25 commit 50a7611
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ TRANSCRIPTION_LANGUAGE=
# It's open source: https://github.com/askrella/speech-rest-api
TTS_ENABLED=false

# Defines if the bot should return the TTS response as a text message too
# If enabled, the bot will send the text response and the voice message
TTS_TRANSCRIPTION_RESPONSE_ENABLED=true

# Defines if the bot should use the Speech API or AWS Polly to convert text to speech
# "speech-api" = It will use our Speech API to transcribe your voice messages
# "aws-polly" = It will use AWS Polly to convert text to speech
Expand Down
8 changes: 8 additions & 0 deletions docs/pages/tts.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ You can enable it by setting the following environment variable:
TTS_ENABLED=true
```

By default, when TTS is enabled, the bot will answer two messages: the text response and the audio response.

You can disable the text response by changing the following environment variable:

```bash
TTS_TRANSCRIPTION_RESPONSE_ENABLED=true
```

## Supported Providers

- [Speech API](#speech-api)
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface IConfig {
whisperApiKey: string;
ttsEnabled: boolean;
ttsMode: TTSMode;
ttsTranscriptionResponse: boolean;
transcriptionEnabled: boolean;
transcriptionMode: TranscriptionMode;
transcriptionLanguage: string;
Expand Down Expand Up @@ -98,6 +99,7 @@ export const config: IConfig = {
// Text-to-Speech
ttsEnabled: getEnvBooleanWithDefault("TTS_ENABLED", false), // Default: false
ttsMode: getEnvTTSMode(), // Default: speech-api
ttsTranscriptionResponse: getEnvBooleanWithDefault("TTS_TRANSCRIPTION_RESPONSE_ENABLED", true), // Default: true

// Transcription
transcriptionEnabled: getEnvBooleanWithDefault("TRANSCRIPTION_ENABLED", false), // Default: false
Expand Down
6 changes: 4 additions & 2 deletions src/handlers/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ async function handleIncomingMessage(message: Message) {
cli.print(`[Transcription] Transcription response: ${transcribedText} (language: ${transcribedLanguage})`);

// Reply with transcription
const reply = `You said: ${transcribedText}${transcribedLanguage ? " (language: " + transcribedLanguage + ")" : ""}`;
message.reply(reply);
if (config.ttsTranscriptionResponse) {
const reply = `You said: ${transcribedText}${transcribedLanguage ? " (language: " + transcribedLanguage + ")" : ""}`;
message.reply(reply);
}

// Handle message GPT
await handleMessageGPT(message, transcribedText);
Expand Down

0 comments on commit 50a7611

Please sign in to comment.