livekit-plugins-google 0.6.1__py3-none-any.whl → 0.6.3__py3-none-any.whl

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.
@@ -20,13 +20,12 @@ __all__ = ["STT", "TTS", "SpeechStream", "__version__"]
20
20
 
21
21
  from livekit.agents import Plugin
22
22
 
23
+ from .log import logger
24
+
23
25
 
24
26
  class GooglePlugin(Plugin):
25
27
  def __init__(self):
26
- super().__init__(__name__, __version__, __package__)
27
-
28
- def download_files(self):
29
- pass
28
+ super().__init__(__name__, __version__, __package__, logger)
30
29
 
31
30
 
32
31
  Plugin.register_plugin(GooglePlugin())
@@ -58,8 +58,11 @@ class STT(stt.STT):
58
58
  credentials_file: str | None = None,
59
59
  ):
60
60
  """
61
- if no credentials is provided, it will use the credentials on the environment
62
- GOOGLE_APPLICATION_CREDENTIALS (default behavior of Google SpeechAsyncClient)
61
+ Create a new instance of Google STT.
62
+
63
+ Credentials must be provided, either by using the ``credentials_info`` dict, or reading
64
+ from the file specified in ``credentials_file`` or the ``GOOGLE_APPLICATION_CREDENTIALS``
65
+ environmental variable.
63
66
  """
64
67
  super().__init__(
65
68
  capabilities=stt.STTCapabilities(streaming=True, interim_results=True)
@@ -212,7 +215,7 @@ class SpeechStream(stt.SpeechStream):
212
215
 
213
216
  async def _run(self, max_retry: int) -> None:
214
217
  retry_count = 0
215
- while not self._input_ch.closed:
218
+ while self._input_ch.qsize() or not self._input_ch.closed:
216
219
  try:
217
220
  # google requires a async generator when calling streaming_recognize
218
221
  # this function basically convert the queue into a async generator
@@ -278,22 +281,22 @@ class SpeechStream(stt.SpeechStream):
278
281
  == cloud_speech.StreamingRecognizeResponse.SpeechEventType.SPEECH_EVENT_TYPE_UNSPECIFIED
279
282
  ):
280
283
  result = resp.results[0]
284
+ speech_data = _streaming_recognize_response_to_speech_data(resp)
285
+ if speech_data is None:
286
+ continue
287
+
281
288
  if not result.is_final:
282
289
  self._event_ch.send_nowait(
283
290
  stt.SpeechEvent(
284
291
  type=stt.SpeechEventType.INTERIM_TRANSCRIPT,
285
- alternatives=[
286
- _streaming_recognize_response_to_speech_data(resp)
287
- ],
292
+ alternatives=[speech_data],
288
293
  )
289
294
  )
290
295
  else:
291
296
  self._event_ch.send_nowait(
292
297
  stt.SpeechEvent(
293
298
  type=stt.SpeechEventType.FINAL_TRANSCRIPT,
294
- alternatives=[
295
- _streaming_recognize_response_to_speech_data(resp)
296
- ],
299
+ alternatives=[speech_data],
297
300
  )
298
301
  )
299
302
 
@@ -337,16 +340,21 @@ def _recognize_response_to_speech_event(
337
340
 
338
341
  def _streaming_recognize_response_to_speech_data(
339
342
  resp: cloud_speech.StreamingRecognizeResponse,
340
- ) -> stt.SpeechData:
343
+ ) -> stt.SpeechData | None:
341
344
  text = ""
342
345
  confidence = 0.0
343
346
  for result in resp.results:
347
+ if len(result.alternatives) == 0:
348
+ continue
344
349
  text += result.alternatives[0].transcript
345
350
  confidence += result.alternatives[0].confidence
346
351
 
347
352
  confidence /= len(resp.results)
348
353
  lg = resp.results[0].language_code
349
354
 
355
+ if text == "":
356
+ return None
357
+
350
358
  data = stt.SpeechData(
351
359
  language=lg, start_time=0, end_time=0, confidence=confidence, text=text
352
360
  )
@@ -51,9 +51,13 @@ class TTS(tts.TTS):
51
51
  credentials_file: str | None = None,
52
52
  ) -> None:
53
53
  """
54
- if no credentials is provided, it will use the credentials on the environment
55
- GOOGLE_APPLICATION_CREDENTIALS (default behavior of Google TextToSpeechAsyncClient)
54
+ Create a new instance of Google TTS.
55
+
56
+ Credentials must be provided, either by using the ``credentials_info`` dict, or reading
57
+ from the file specified in ``credentials_file`` or the ``GOOGLE_APPLICATION_CREDENTIALS``
58
+ environmental variable.
56
59
  """
60
+
57
61
  super().__init__(
58
62
  capabilities=tts.TTSCapabilities(
59
63
  streaming=False,
@@ -12,4 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- __version__ = "0.6.1"
15
+ __version__ = "0.6.3"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: livekit-plugins-google
3
- Version: 0.6.1
3
+ Version: 0.6.3
4
4
  Summary: Agent Framework plugin for services from Google Cloud
5
5
  Home-page: https://github.com/livekit/agents
6
6
  License: Apache-2.0
@@ -0,0 +1,11 @@
1
+ livekit/plugins/google/__init__.py,sha256=CYbSmm5fEw71F_r_4pEApGaWQ_r15Y3ZEocH88a4yc8,948
2
+ livekit/plugins/google/log.py,sha256=GI3YWN5YzrafnUccljzPRS_ZALkMNk1i21IRnTl2vNA,69
3
+ livekit/plugins/google/models.py,sha256=n8pgTJ7xyJpPCZJ_y0GzaQq6LqYknL6K6trpi07-AxM,1307
4
+ livekit/plugins/google/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ livekit/plugins/google/stt.py,sha256=6yhDKrhVA4uANY9INtKG3p0FeMHPuHgi7Ny6swlwbHg,13129
6
+ livekit/plugins/google/tts.py,sha256=aHmFFViGTBuN8NVyt7h83t6J50hnCZO94SD9X71tAlI,5644
7
+ livekit/plugins/google/version.py,sha256=BHsM7CdYSULy_oyTN7Tl5mOCCZ-CmE_4ARJPeHOpqVM,600
8
+ livekit_plugins_google-0.6.3.dist-info/METADATA,sha256=kmLq8JvGH0F_Er1OQUzlSFt3hYuQPZib2MRr0DUnMnA,1584
9
+ livekit_plugins_google-0.6.3.dist-info/WHEEL,sha256=ixB2d4u7mugx_bCBycvM9OzZ5yD7NmPXFRtKlORZS2Y,91
10
+ livekit_plugins_google-0.6.3.dist-info/top_level.txt,sha256=OoDok3xUmXbZRvOrfvvXB-Juu4DX79dlq188E19YHoo,8
11
+ livekit_plugins_google-0.6.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (71.1.0)
2
+ Generator: setuptools (74.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,11 +0,0 @@
1
- livekit/plugins/google/__init__.py,sha256=DlQC5cosMFyQlM8_vFvJGoZiziFkd0Sa4mutnsxXyZM,959
2
- livekit/plugins/google/log.py,sha256=GI3YWN5YzrafnUccljzPRS_ZALkMNk1i21IRnTl2vNA,69
3
- livekit/plugins/google/models.py,sha256=n8pgTJ7xyJpPCZJ_y0GzaQq6LqYknL6K6trpi07-AxM,1307
4
- livekit/plugins/google/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- livekit/plugins/google/stt.py,sha256=M8ybqoD72qX-hzjMc6iCHTHxCNpWGKymg_ghF5OJRfA,12944
6
- livekit/plugins/google/tts.py,sha256=jvbw-T-JlVxcYWiF-tCox35LZuCN3DBKwDp3zN8JCTw,5549
7
- livekit/plugins/google/version.py,sha256=VuvtIt3FphjfrQRjPSUJA5MBuzWXY-hZr6Xa40x487A,600
8
- livekit_plugins_google-0.6.1.dist-info/METADATA,sha256=spmwpbsVi4TeFMWv11ToHzSoNcA9V762hxSeJCXIJtI,1584
9
- livekit_plugins_google-0.6.1.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
10
- livekit_plugins_google-0.6.1.dist-info/top_level.txt,sha256=OoDok3xUmXbZRvOrfvvXB-Juu4DX79dlq188E19YHoo,8
11
- livekit_plugins_google-0.6.1.dist-info/RECORD,,