livekit-plugins-volcenginee 1.3.5__tar.gz → 1.3.6__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.
@@ -5,3 +5,4 @@ __pycache__/
5
5
  .env
6
6
  .env.*
7
7
  dist/
8
+ latency_agent.py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: livekit-plugins-volcenginee
3
- Version: 1.3.5
3
+ Version: 1.3.6
4
4
  Summary: LiveKit Agent Plugins for Volcengine
5
5
  Author-email: linsanzhu <2287225730@qq.com>
6
6
  Keywords: audio,livekit,realtime,video,webrtc
@@ -259,7 +259,7 @@ class RealtimeModel(llm.RealtimeModel):
259
259
  speaking_style: str = "你的说话风格简洁明了,语速适中,语调自然。",
260
260
  speaker: str = "zh_female_vv_jupiter_bigtts",
261
261
  opening: str | None = None,
262
- api_key: str | None = None,
262
+ api_key: NotGivenOr[str] = NOT_GIVEN,
263
263
  system_role: str | None = None,
264
264
  character_manifest: str = None,
265
265
  model: Literal["O", "SC"] = "O",
@@ -295,9 +295,12 @@ class RealtimeModel(llm.RealtimeModel):
295
295
  logger.info(
296
296
  f"Volc Websearch No Result Message: {volc_websearch_no_result_message}"
297
297
  )
298
- api_key = api_key or os.environ.get("VOLCENGINE_REALTIME_API_KEY")
298
+ api_key = api_key if utils.is_given(api_key) else os.environ.get("VOLCENGINE_REALTIME_API_KEY")
299
299
  if api_key is None:
300
- raise ValueError("VOLCENGINE_REALTIME_API_KEY is required")
300
+ raise ValueError(
301
+ "api_key is required (pass it explicitly or set the "
302
+ "VOLCENGINE_REALTIME_API_KEY environment variable)"
303
+ )
301
304
  self._opts = _RealtimeOptions(
302
305
  api_key=api_key,
303
306
  bot_name=bot_name,
@@ -22,7 +22,7 @@ from livekit.agents.types import (
22
22
  NOT_GIVEN,
23
23
  NotGivenOr,
24
24
  )
25
- from livekit.agents.utils import AudioBuffer
25
+ from livekit.agents.utils import AudioBuffer, is_given
26
26
 
27
27
  from .log import logger
28
28
 
@@ -180,7 +180,7 @@ class STT(stt.STT):
180
180
  def __init__(
181
181
  self,
182
182
  *,
183
- api_key: str | None = None,
183
+ api_key: NotGivenOr[str] = NOT_GIVEN,
184
184
  base_url: str = "wss://openspeech.bytedance.com/api/v3/sauc/bigmodel",
185
185
  resource_id: str | None = None,
186
186
  model_name: str = "bigmodel",
@@ -199,6 +199,13 @@ class STT(stt.STT):
199
199
  )
200
200
  )
201
201
 
202
+ api_key = api_key if is_given(api_key) else os.getenv("VOLCENGINE_STT_API_KEY")
203
+ if api_key is None:
204
+ raise ValueError(
205
+ "api_key is required (pass it explicitly or set the "
206
+ "VOLCENGINE_STT_API_KEY environment variable)"
207
+ )
208
+
202
209
  self._opts = STTOptions(
203
210
  base_url=base_url,
204
211
  api_key=api_key,
@@ -19,7 +19,12 @@ from livekit.agents import (
19
19
  tts,
20
20
  utils,
21
21
  )
22
- from livekit.agents.types import DEFAULT_API_CONNECT_OPTIONS
22
+ from livekit.agents.types import (
23
+ DEFAULT_API_CONNECT_OPTIONS,
24
+ NOT_GIVEN,
25
+ NotGivenOr,
26
+ )
27
+ from livekit.agents.utils import is_given
23
28
 
24
29
  from .log import logger
25
30
 
@@ -104,28 +109,44 @@ class _TTSOptions(BaseModel):
104
109
  class TTS(tts.TTS):
105
110
  def __init__(
106
111
  self,
107
- api_key: str,
112
+ *,
113
+ api_key: NotGivenOr[str] = NOT_GIVEN,
108
114
  resource_id: str | None = None,
109
115
  voice: str = "zh_female_xiaohe_uranus_bigtts",
110
116
  speed: float = 1.0,
111
117
  volume: float = 1.0,
112
118
  pitch: float = 1.0,
119
+ min_sentence_length: int = 10,
113
120
  sample_rate: Literal[24000, 16000, 8000] = 16000,
114
121
  http_session: aiohttp.ClientSession | None = None,
115
122
  ):
116
123
  """VolcEngine TTS
117
124
 
118
125
  Args:
119
- api_key (str): the API key of the tts, you can get it from the new console.
126
+ api_key (NotGivenOr[str], optional): the API key of the tts, you can get it from the new console.
127
+ Falls back to the ``VOLCENGINE_TTS_API_KEY`` environment variable when not provided.
120
128
  resource_id (str | None, optional): VolcEngine TTS resource id. Use `seed-tts-2.0` for Doubao TTS 2.0 voices, `seed-tts-1.0` / `seed-tts-1.0-concurr` for Doubao TTS 1.0 voices, `seed-icl-2.0` for voice cloning 2.0, and `seed-icl-1.0` / `seed-icl-1.0-concurr` for voice cloning 1.0. Defaults to None.
121
129
  voice (str, optional): the voice id used by the tts request. Defaults to `zh_female_xiaohe_uranus_bigtts`.
122
130
  speed (float, optional): speech rate multiplier (OpenAI-style). Range [0.2, 3.0]; 1.0 = normal, 2.0 = 2x, 0.5 = 0.5x. Internally converted to the Volcengine ``speech_rate`` int. Defaults to 1.0.
123
131
  volume (float, optional): volume multiplier (OpenAI-style). Range (0.1, 3.0]; 1.0 = normal, 2.0 = 2x, 0.5 = 0.5x. Internally converted to the Volcengine ``loudness_rate`` int. Not supported for mix voices. Defaults to 1.0.
124
132
  pitch (float, optional): kept for backwards compatibility, not currently sent to the API. Defaults to 1.0.
133
+ min_sentence_length (int, optional): minimum number of characters
134
+ (Chinese chars / tokens) the internal ``TextStreamSentencizer``
135
+ must accumulate before yielding a sentence to TTS. Lower
136
+ values trade off TTS efficiency (more / shorter requests)
137
+ against latency — useful for short-reply agents where the
138
+ model often returns <10 chars. Defaults to 10 (the upstream
139
+ default; matches the legacy behavior).
125
140
  sample_rate (Literal[24000, 16000, 8000], optional): the sample rate of the tts. Defaults to 16000.
126
141
  streaming (bool, optional): whether to use the streaming api. Defaults to True.
127
142
  http_session (aiohttp.ClientSession | None, optional): the http session to use. Defaults to None.
128
143
  """
144
+ api_key = api_key if is_given(api_key) else os.getenv("VOLCENGINE_TTS_API_KEY")
145
+ if api_key is None:
146
+ raise ValueError(
147
+ "api_key is required (pass it explicitly or set the "
148
+ "VOLCENGINE_TTS_API_KEY environment variable)"
149
+ )
129
150
  super().__init__(
130
151
  capabilities=tts.TTSCapabilities(streaming=True),
131
152
  sample_rate=sample_rate,
@@ -141,6 +162,7 @@ class TTS(tts.TTS):
141
162
  pitch=pitch,
142
163
  )
143
164
  self._session = http_session
165
+ self._min_sentence_length = min_sentence_length
144
166
  self._streams = weakref.WeakSet[SynthesizeStream]()
145
167
 
146
168
  def _ensure_session(self) -> aiohttp.ClientSession:
@@ -159,6 +181,7 @@ class TTS(tts.TTS):
159
181
  conn_options=conn_options,
160
182
  opts=self._opts,
161
183
  session=self._ensure_session(),
184
+ min_sentence_length=self._min_sentence_length,
162
185
  )
163
186
  self._streams.add(stream)
164
187
  return stream
@@ -178,15 +201,19 @@ class SynthesizeStream(tts.SynthesizeStream):
178
201
  session: aiohttp.ClientSession,
179
202
  tts: TTS,
180
203
  conn_options=None,
204
+ min_sentence_length: int = 10,
181
205
  ):
182
206
  super().__init__(tts=tts, conn_options=conn_options)
183
207
  self._opts: _TTSOptions = opts
184
208
  self._session = session
209
+ self._min_sentence_length = min_sentence_length
185
210
 
186
211
  async def _run(self, emitter: tts.AudioEmitter):
187
212
  request_id = utils.shortuuid()
188
213
 
189
- sentence_splitter = TextStreamSentencizer()
214
+ sentence_splitter = TextStreamSentencizer(
215
+ min_sentence_length=self._min_sentence_length
216
+ )
190
217
  emitter.initialize(
191
218
  request_id=request_id,
192
219
  sample_rate=self._opts.sample_rate,
@@ -0,0 +1 @@
1
+ __version__ = "1.3.6"
@@ -1 +0,0 @@
1
- __version__ = "1.3.5"