Skip to content

Commit 94feaf2

Browse files
committed
chore(dependencies): Update development dependencies and remove unused real-time TTS components
- Reformatted the `dev` dependencies in `pyproject.toml` for better readability - Added `elevenlabs` package to development dependencies - Updated `agentle` package version to `0.9.15` - Removed unused real-time TTS classes and definitions to streamline the codebase
1 parent ed66211 commit 94feaf2

18 files changed

+255
-176
lines changed

agentle/tts/audio_format.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from typing import Literal
2+
3+
4+
AudioFormat = Literal[
5+
"audio/mpeg", "audio/wav", "audio/opus", "audio/basic", "application/octet-stream"
6+
]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import base64
2+
from collections.abc import AsyncIterator
3+
from typing import override
4+
5+
from agentle.tts.audio_format import AudioFormat
6+
from agentle.tts.output_format_type import OutputFormatType
7+
from agentle.tts.speech_config import SpeechConfig
8+
from agentle.tts.speech_result import SpeechResult
9+
from agentle.tts.tts_provider import TtsProvider
10+
from agentle.utils.needs import needs
11+
12+
13+
class ElevenLabsTtsProvider(TtsProvider):
14+
@override
15+
@needs("elevenlabs")
16+
async def synthesize(self, text: str, config: SpeechConfig) -> SpeechResult:
17+
from elevenlabs import AsyncElevenLabs
18+
from elevenlabs.types.voice_settings import (
19+
VoiceSettings as ElevenLabsVoiceSettings,
20+
)
21+
22+
elevenlabs = AsyncElevenLabs()
23+
audio_stream: AsyncIterator[bytes] = elevenlabs.text_to_speech.convert(
24+
text=text,
25+
voice_id=config.voice_id,
26+
model_id=config.model_id,
27+
output_format=config.output_format,
28+
voice_settings=ElevenLabsVoiceSettings(
29+
stability=config.voice_settings.stability,
30+
use_speaker_boost=config.voice_settings.use_speaker_boost,
31+
similarity_boost=config.voice_settings.similarity_boost,
32+
style=config.voice_settings.style,
33+
speed=config.voice_settings.speed,
34+
)
35+
if config.voice_settings
36+
else None,
37+
language_code=config.language_code,
38+
)
39+
40+
# Collect all chunks into bytes
41+
chunks: list[bytes] = []
42+
async for chunk in audio_stream:
43+
chunks.append(chunk)
44+
audio_bytes = b"".join(chunks)
45+
46+
audio_base64 = base64.b64encode(audio_bytes).decode("utf-8")
47+
48+
return SpeechResult(
49+
audio=audio_base64,
50+
mime_type=self._get_mime_type(config.output_format),
51+
format=config.output_format,
52+
)
53+
54+
def _get_mime_type(self, output_format: OutputFormatType) -> AudioFormat:
55+
"""Convert ElevenLabs output format to MIME type."""
56+
if output_format.startswith("mp3_"):
57+
return "audio/mpeg"
58+
elif output_format.startswith("pcm_"):
59+
return "audio/wav" # or "audio/pcm" depending on your use case
60+
elif output_format.startswith("ulaw_"):
61+
return "audio/basic"
62+
elif output_format.startswith("alaw_"):
63+
return "audio/basic"
64+
elif output_format.startswith("opus_"):
65+
return "audio/opus"
66+
else:
67+
return "application/octet-stream" # fallback

agentle/tts/output_format_type.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from typing import Literal
2+
3+
4+
OutputFormatType = Literal[
5+
"mp3_22050_32",
6+
"mp3_24000_48",
7+
"mp3_44100_32",
8+
"mp3_44100_64",
9+
"mp3_44100_96",
10+
"mp3_44100_128",
11+
"mp3_44100_192",
12+
"pcm_8000",
13+
"pcm_16000",
14+
"pcm_22050",
15+
"pcm_24000",
16+
"pcm_32000",
17+
"pcm_44100",
18+
"pcm_48000",
19+
"ulaw_8000",
20+
"alaw_8000",
21+
"opus_48000_32",
22+
"opus_48000_64",
23+
"opus_48000_96",
24+
"opus_48000_128",
25+
"opus_48000_192",
26+
]

agentle/tts/real_time/definitions/audio_data.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

agentle/tts/real_time/definitions/speech_config.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

agentle/tts/real_time/definitions/speech_result.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

agentle/tts/real_time/definitions/tts_stream_chunk.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

agentle/tts/real_time/definitions/voice_gender.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

agentle/tts/real_time/definitions/voice_info.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

agentle/tts/real_time/real_time_speech_to_text_provider.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)