swarmauri_agent_texttospeech 0.11.0.dev4__tar.gz → 0.11.0.dev6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: swarmauri_agent_texttospeech
3
- Version: 0.11.0.dev4
3
+ Version: 0.11.0.dev6
4
4
  Summary: Stateless Swarmauri agent for converting independent text prompts into audio through any TTSBase provider.
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
@@ -20,8 +20,8 @@ Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Programming Language :: Python :: 3.12
21
21
  Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
22
22
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
- Requires-Dist: swarmauri_base
24
- Requires-Dist: swarmauri_core
23
+ Requires-Dist: swarmauri_base (>=0.11.0.dev12,<0.12)
24
+ Requires-Dist: swarmauri_core (>=0.11.0.dev7,<0.12)
25
25
  Description-Content-Type: text/markdown
26
26
 
27
27
  ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
@@ -55,16 +55,16 @@ uv add swarmauri_agent_texttospeech
55
55
  pip install swarmauri_agent_texttospeech
56
56
  ```
57
57
 
58
- Install a TTS provider package alongside the agent. For PlayHT:
58
+ Install a TTS provider package alongside the agent. For the alpha OpenAI provider:
59
59
 
60
60
  ```bash
61
- uv add swarmauri_tts_playht
61
+ uv add --prerelease allow swarmauri_tts_openai
62
62
  ```
63
63
 
64
64
  Or with `pip`:
65
65
 
66
66
  ```bash
67
- pip install swarmauri_tts_playht
67
+ pip install --pre swarmauri_tts_openai
68
68
  ```
69
69
 
70
70
  ## Usage
@@ -73,13 +73,12 @@ pip install swarmauri_tts_playht
73
73
  import os
74
74
 
75
75
  from swarmauri_agent_texttospeech import TextToSpeechAgent
76
- from swarmauri_tts_playht import PlayHTModel
76
+ from swarmauri_tts_openai import OpenaiTTS
77
77
 
78
- tts = PlayHTModel(
79
- api_key=os.environ["PLAYHT_API_KEY"],
80
- user_id=os.environ["PLAYHT_USER_ID"],
81
- name="Play3.0-mini",
82
- voice="Adolfo",
78
+ tts = OpenaiTTS(
79
+ api_key=os.environ["OPENAI_API_KEY"],
80
+ name="gpt-4o-mini-tts",
81
+ voice="alloy",
83
82
  )
84
83
  agent = TextToSpeechAgent(tts=tts, output_path="greeting.mp3")
85
84
 
@@ -90,6 +89,40 @@ print(audio_path)
90
89
  Each call is independent. The agent passes only that call's text to the TTS
91
90
  provider and never constructs a conversation or system message.
92
91
 
92
+ ## Structured dialogue and bounded batches
93
+
94
+ The agent also forwards a nonempty tuple of typed dialogue turns unchanged:
95
+
96
+ ```python
97
+ import os
98
+
99
+ from swarmauri_agent_texttospeech import TextToSpeechAgent
100
+ from swarmauri_tts_gemini_dialogue import (
101
+ GeminiDialogueTTS, GeminiDialogueTurn,
102
+ )
103
+
104
+ provider = GeminiDialogueTTS(
105
+ api_key=os.environ["GEMINI_API_KEY"],
106
+ speaker_voices={"A": "Puck", "B": "Kore"},
107
+ )
108
+ agent = TextToSpeechAgent(tts=provider, output_path="dialogue.wav")
109
+ turns = (
110
+ GeminiDialogueTurn(text="Hello", speaker="A"),
111
+ GeminiDialogueTurn(text="Hello back", speaker="B"),
112
+ )
113
+ agent.exec(turns)
114
+ # await agent.abatch([turns], max_concurrent=2)
115
+ ```
116
+
117
+ Speaker and voice validation belongs to the selected provider. A JSON string
118
+ is not parsed into turns. Set filenames to match the codec; Gemini/native
119
+ DeepInfra WAV defaults require .wav paths. Async batches default to at most
120
+ five concurrent calls, with a positive integer max_concurrent override.
121
+
122
+ The OpenAI Speech example above is temporary compatibility: its models have a
123
+ scheduled 2027-01-06 shutdown. All new provider packages remain alpha and live
124
+ verification is pending; see the SDK migration and verification guides.
125
+
93
126
  ## Contributing
94
127
 
95
128
  This package is part of the
@@ -100,3 +133,7 @@ should follow the repository contribution and style guides.
100
133
 
101
134
  Apache-2.0
102
135
 
136
+ Provider instances are validated against TTSBase at call-time construction, so
137
+ providers imported after the agent class remain usable. Serialized providers
138
+ retain their concrete fields; import that provider before deserialization.
139
+
@@ -29,16 +29,16 @@ uv add swarmauri_agent_texttospeech
29
29
  pip install swarmauri_agent_texttospeech
30
30
  ```
31
31
 
32
- Install a TTS provider package alongside the agent. For PlayHT:
32
+ Install a TTS provider package alongside the agent. For the alpha OpenAI provider:
33
33
 
34
34
  ```bash
35
- uv add swarmauri_tts_playht
35
+ uv add --prerelease allow swarmauri_tts_openai
36
36
  ```
37
37
 
38
38
  Or with `pip`:
39
39
 
40
40
  ```bash
41
- pip install swarmauri_tts_playht
41
+ pip install --pre swarmauri_tts_openai
42
42
  ```
43
43
 
44
44
  ## Usage
@@ -47,13 +47,12 @@ pip install swarmauri_tts_playht
47
47
  import os
48
48
 
49
49
  from swarmauri_agent_texttospeech import TextToSpeechAgent
50
- from swarmauri_tts_playht import PlayHTModel
50
+ from swarmauri_tts_openai import OpenaiTTS
51
51
 
52
- tts = PlayHTModel(
53
- api_key=os.environ["PLAYHT_API_KEY"],
54
- user_id=os.environ["PLAYHT_USER_ID"],
55
- name="Play3.0-mini",
56
- voice="Adolfo",
52
+ tts = OpenaiTTS(
53
+ api_key=os.environ["OPENAI_API_KEY"],
54
+ name="gpt-4o-mini-tts",
55
+ voice="alloy",
57
56
  )
58
57
  agent = TextToSpeechAgent(tts=tts, output_path="greeting.mp3")
59
58
 
@@ -64,6 +63,40 @@ print(audio_path)
64
63
  Each call is independent. The agent passes only that call's text to the TTS
65
64
  provider and never constructs a conversation or system message.
66
65
 
66
+ ## Structured dialogue and bounded batches
67
+
68
+ The agent also forwards a nonempty tuple of typed dialogue turns unchanged:
69
+
70
+ ```python
71
+ import os
72
+
73
+ from swarmauri_agent_texttospeech import TextToSpeechAgent
74
+ from swarmauri_tts_gemini_dialogue import (
75
+ GeminiDialogueTTS, GeminiDialogueTurn,
76
+ )
77
+
78
+ provider = GeminiDialogueTTS(
79
+ api_key=os.environ["GEMINI_API_KEY"],
80
+ speaker_voices={"A": "Puck", "B": "Kore"},
81
+ )
82
+ agent = TextToSpeechAgent(tts=provider, output_path="dialogue.wav")
83
+ turns = (
84
+ GeminiDialogueTurn(text="Hello", speaker="A"),
85
+ GeminiDialogueTurn(text="Hello back", speaker="B"),
86
+ )
87
+ agent.exec(turns)
88
+ # await agent.abatch([turns], max_concurrent=2)
89
+ ```
90
+
91
+ Speaker and voice validation belongs to the selected provider. A JSON string
92
+ is not parsed into turns. Set filenames to match the codec; Gemini/native
93
+ DeepInfra WAV defaults require .wav paths. Async batches default to at most
94
+ five concurrent calls, with a positive integer max_concurrent override.
95
+
96
+ The OpenAI Speech example above is temporary compatibility: its models have a
97
+ scheduled 2027-01-06 shutdown. All new provider packages remain alpha and live
98
+ verification is pending; see the SDK migration and verification guides.
99
+
67
100
  ## Contributing
68
101
 
69
102
  This package is part of the
@@ -73,3 +106,7 @@ should follow the repository contribution and style guides.
73
106
  ## License
74
107
 
75
108
  Apache-2.0
109
+
110
+ Provider instances are validated against TTSBase at call-time construction, so
111
+ providers imported after the agent class remain usable. Serialized providers
112
+ retain their concrete fields; import that provider before deserialization.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "swarmauri_agent_texttospeech"
3
- version = "0.11.0.dev4"
3
+ version = "0.11.0.dev6"
4
4
  description = "Stateless Swarmauri agent for converting independent text prompts into audio through any TTSBase provider."
5
5
  license = "Apache-2.0"
6
6
  readme = "README.md"
@@ -22,8 +22,8 @@ classifiers = [
22
22
  ]
23
23
  authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
24
24
  dependencies = [
25
- "swarmauri_core",
26
- "swarmauri_base",
25
+ "swarmauri_core>=0.11.0.dev7,<0.12",
26
+ "swarmauri_base>=0.11.0.dev12,<0.12",
27
27
  ]
28
28
  keywords = [
29
29
  "swarmauri",
@@ -38,7 +38,10 @@ keywords = [
38
38
 
39
39
  [tool.uv.sources]
40
40
  swarmauri_core = { workspace = true }
41
+ swarmauri_tts_openai = { workspace = true }
41
42
  swarmauri_base = { workspace = true }
43
+ swarmauri_tts_elevenlabs_dialogue = { workspace = true }
44
+ swarmauri_tts_gemini_dialogue = { workspace = true }
42
45
 
43
46
  [project.entry-points.'swarmauri.agents']
44
47
  TextToSpeechAgent = "swarmauri_agent_texttospeech:TextToSpeechAgent"
@@ -54,6 +57,9 @@ build-backend = "poetry.core.masonry.api"
54
57
 
55
58
  [dependency-groups]
56
59
  dev = [
60
+ "swarmauri_tts_openai>=0.1.0a2,<0.2",
61
+ "swarmauri_tts_elevenlabs_dialogue>=0.1.0a1,<0.2",
62
+ "swarmauri_tts_gemini_dialogue>=0.1.0a1,<0.2",
57
63
  "pytest>=8.0",
58
64
  "pytest-asyncio>=0.24.0",
59
65
  "ruff>=0.9.9",
@@ -7,9 +7,15 @@ from collections.abc import Sequence
7
7
  from pathlib import Path
8
8
  from typing import Any, Dict, List, Literal, Optional, Union
9
9
 
10
- from pydantic import ConfigDict, Field
11
-
12
- from swarmauri_base.ComponentBase import ComponentBase, SubclassUnion
10
+ from pydantic import (
11
+ BaseModel,
12
+ ConfigDict,
13
+ Field,
14
+ SerializeAsAny,
15
+ field_validator,
16
+ )
17
+
18
+ from swarmauri_base.ComponentBase import ComponentBase
13
19
  from swarmauri_base.agents.AgentBase import AgentBase
14
20
  from swarmauri_base.tts.TTSBase import TTSBase
15
21
  from swarmauri_core.messages.IMessage import IMessage
@@ -21,27 +27,32 @@ class TextToSpeechAgent(AgentBase):
21
27
 
22
28
  llm: None = Field(default=None, exclude=True)
23
29
  llm_kwargs: None = Field(default=None, exclude=True)
24
- tts: SubclassUnion[TTSBase]
30
+ tts: SerializeAsAny[TTSBase]
25
31
  output_path: str = "output.mp3"
26
32
  tts_kwargs: Dict[str, Any] = Field(default_factory=dict)
27
33
  model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
28
34
  type: Literal["TextToSpeechAgent"] = "TextToSpeechAgent"
29
35
 
30
- def model_post_init(self, __context: Any) -> None:
31
- """Rehydrate a serialized TTS component through its base registry."""
32
- if not isinstance(self.tts, dict):
33
- return
34
- type_name = self.tts.get("type")
36
+ @field_validator("tts", mode="before")
37
+ @classmethod
38
+ def _restore_tts(cls, value):
39
+ """Resolve serialized providers at validation time, after discovery."""
40
+ if not isinstance(value, dict):
41
+ return value
42
+ type_name = value.get("type")
35
43
  registry = TTSBase._registry.get("TTSBase", {})
36
44
  tts_class = registry.get("subtypes", {}).get(type_name)
37
45
  if tts_class is None and type_name == "TTSBase":
38
46
  tts_class = registry.get("model_cls", TTSBase)
39
- if tts_class is not None:
40
- self.tts = tts_class.model_validate(self.tts)
47
+ if tts_class is None:
48
+ raise ValueError(
49
+ "Import the serialized TTS provider before loading it."
50
+ )
51
+ return tts_class.model_validate(value)
41
52
 
42
53
  def exec(
43
54
  self,
44
- input_str: Optional[Union[str, IMessage]] = "",
55
+ input_str: Optional[Union[str, IMessage, tuple[BaseModel, ...]]] = "",
45
56
  llm_kwargs: Optional[Dict] = None,
46
57
  *,
47
58
  audio_path: Optional[str] = None,
@@ -58,7 +69,7 @@ class TextToSpeechAgent(AgentBase):
58
69
 
59
70
  async def aexec(
60
71
  self,
61
- input_str: Optional[Union[str, IMessage]] = "",
72
+ input_str: Optional[Union[str, IMessage, tuple[BaseModel, ...]]] = "",
62
73
  llm_kwargs: Optional[Dict] = None,
63
74
  *,
64
75
  audio_path: Optional[str] = None,
@@ -75,7 +86,7 @@ class TextToSpeechAgent(AgentBase):
75
86
 
76
87
  def batch(
77
88
  self,
78
- inputs: List[Union[str, IMessage]],
89
+ inputs: List[Union[str, IMessage, tuple[BaseModel, ...]]],
79
90
  llm_kwargs: Optional[Dict] = None,
80
91
  *,
81
92
  audio_paths: Optional[Sequence[str]] = None,
@@ -95,35 +106,57 @@ class TextToSpeechAgent(AgentBase):
95
106
 
96
107
  async def abatch(
97
108
  self,
98
- inputs: List[Union[str, IMessage]],
109
+ inputs: List[Union[str, IMessage, tuple[BaseModel, ...]]],
99
110
  llm_kwargs: Optional[Dict] = None,
100
111
  *,
101
112
  audio_paths: Optional[Sequence[str]] = None,
102
113
  tts_kwargs: Optional[Dict[str, Any]] = None,
114
+ max_concurrent: int = 5,
103
115
  ) -> List[str]:
104
- """Concurrently synthesize independent inputs."""
116
+ """Synthesize independent inputs with bounded concurrency."""
117
+ if (
118
+ isinstance(max_concurrent, bool)
119
+ or not isinstance(max_concurrent, int)
120
+ or max_concurrent < 1
121
+ ):
122
+ raise ValueError("max_concurrent must be a positive integer.")
105
123
  paths = self._resolve_batch_paths(len(inputs), audio_paths)
106
- return await asyncio.gather(
107
- *[
108
- self.aexec(
124
+ semaphore = asyncio.Semaphore(max_concurrent)
125
+
126
+ async def generate(input_data, path):
127
+ async with semaphore:
128
+ return await self.aexec(
109
129
  input_data,
110
130
  llm_kwargs=llm_kwargs,
111
131
  audio_path=path,
112
132
  tts_kwargs=tts_kwargs,
113
133
  )
134
+
135
+ return await asyncio.gather(
136
+ *(
137
+ generate(input_data, path)
114
138
  for input_data, path in zip(inputs, paths)
115
- ]
139
+ )
116
140
  )
117
141
 
118
142
  @staticmethod
119
- def _input_text(input_data: Optional[Union[str, IMessage]]) -> str:
143
+ def _input_text(
144
+ input_data: Optional[Union[str, IMessage, tuple[BaseModel, ...]]],
145
+ ) -> Union[str, tuple[BaseModel, ...]]:
146
+ if (
147
+ isinstance(input_data, tuple)
148
+ and input_data
149
+ and all(isinstance(turn, BaseModel) for turn in input_data)
150
+ ):
151
+ return input_data
120
152
  if isinstance(input_data, str):
121
153
  text = input_data
122
154
  elif isinstance(input_data, IMessage):
123
155
  text = input_data.content
124
156
  else:
125
157
  raise TypeError(
126
- "Input must be text or an IMessage with text content."
158
+ "Input must be text, an IMessage, "
159
+ "or a nonempty tuple of typed dialogue turns."
127
160
  )
128
161
 
129
162
  if not isinstance(text, str):