Skip to content

Commit bbd60d6

Browse files
committed
removed audio speed config
1 parent b7391ae commit bbd60d6

File tree

2 files changed

+8
-31
lines changed

2 files changed

+8
-31
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ docker run -d -e OPENAI_API_KEY=<YOUR_API_KEY> -e TTS_PROVIDER=EDGETTS -e EDGETT
4141
## Notes
4242
The AI model defaults to `gpt-3.5-turbo` but you can adjust this by setting the `AI_COMPLETION_MODEL` environment variable (e.g. to `gpt-4` if your `OPENAI_API_KEY` has access to it)
4343

44-
Output audio speed can be adjusted by setting the `AUDIO_SPEED` environment variable e.g. setting this to 1.5 will result in audio playing back at 1.5x default speed.
45-
4644
You can configure the language by setting the `LANGUAGE` environment variable to the corresponding ISO-639-1 code. The default is `en`.
4745
Languages other than English are currently only supported when using the `gTTS` or `edge_tts` providers for text-to-speech. The TTS provider can be selected by setting the environment variable `TTS_PROVIDER` to one of the values in [tts.py](./app/tts.py).
4846

backend/tts.py

+8-29
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55

66
import requests
77
from gtts import gTTS
8-
from pydub import AudioSegment
98
import edge_tts
109
from elevenlabs import generate, save
1110

1211
from util import delete_file
1312

1413
LANGUAGE = os.getenv("LANGUAGE", "en")
15-
AUDIO_SPEED = os.getenv("AUDIO_SPEED", None)
1614
TTS_PROVIDER = os.getenv("TTS_PROVIDER", "EDGETTS")
1715

1816
ELEVENLABS_API_KEY = os.getenv("ELEVENLABS_API_KEY", None)
@@ -40,11 +38,10 @@ async def _edge_tts_to_speech(text, background_tasks):
4038
filepath = f"/tmp/{uuid.uuid4()}.mp3"
4139
await communicate.save(filepath)
4240

43-
speed_adjusted_filepath = _adjust_audio_speed(filepath)
44-
background_tasks.add_task(delete_file, speed_adjusted_filepath)
41+
background_tasks.add_task(delete_file, filepath)
4542

4643
logging.info('TTS time: %s %s', time.time() - start_time, 'seconds')
47-
return speed_adjusted_filepath
44+
return filepath
4845

4946

5047
def _gtts_to_speech(text, background_tasks):
@@ -54,11 +51,10 @@ def _gtts_to_speech(text, background_tasks):
5451
filepath = f"/tmp/{uuid.uuid4()}.mp3"
5552
tts.save(filepath)
5653

57-
speed_adjusted_filepath = _adjust_audio_speed(filepath)
58-
background_tasks.add_task(delete_file, speed_adjusted_filepath)
54+
background_tasks.add_task(delete_file, filepath)
5955

6056
logging.info('TTS time: %s %s', time.time() - start_time, 'seconds')
61-
return speed_adjusted_filepath
57+
return filepath
6258

6359

6460
def _elevenlabs_to_speech(text, background_tasks):
@@ -74,11 +70,10 @@ def _elevenlabs_to_speech(text, background_tasks):
7470
filepath = f"/tmp/{uuid.uuid4()}.mp3"
7571
save(audio, filepath)
7672

77-
speed_adjusted_filepath = _adjust_audio_speed(filepath)
78-
background_tasks.add_task(delete_file, speed_adjusted_filepath)
73+
background_tasks.add_task(delete_file, filepath)
7974

8075
logging.info('TTS time: %s %s', time.time() - start_time, 'seconds')
81-
return speed_adjusted_filepath
76+
return filepath
8277

8378

8479
def _streamelements_to_speech(text, background_tasks):
@@ -90,23 +85,7 @@ def _streamelements_to_speech(text, background_tasks):
9085
with open(filepath, "wb") as f:
9186
f.write(response.content)
9287

93-
speed_adjusted_filepath = _adjust_audio_speed(filepath)
94-
background_tasks.add_task(delete_file, speed_adjusted_filepath)
88+
background_tasks.add_task(delete_file, filepath)
9589

9690
logging.info('TTS time: %s %s', time.time() - start_time, 'seconds')
97-
return speed_adjusted_filepath
98-
99-
100-
def _adjust_audio_speed(audio_filepath):
101-
if AUDIO_SPEED is None:
102-
return audio_filepath
103-
104-
audio = AudioSegment.from_mp3(audio_filepath)
105-
faster_audio = audio.speedup(playback_speed=float(AUDIO_SPEED))
106-
107-
speed_adjusted_filepath = f"/tmp/{uuid.uuid4()}.mp3"
108-
faster_audio.export(speed_adjusted_filepath, format="mp3")
109-
110-
delete_file(audio_filepath)
111-
112-
return speed_adjusted_filepath
91+
return filepath

0 commit comments

Comments
 (0)