livekit-plugins-google 0.6.3__py3-none-any.whl → 0.7.1__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.
@@ -16,13 +16,14 @@ from __future__ import annotations
16
16
 
17
17
  import asyncio
18
18
  import dataclasses
19
- import os
20
19
  from dataclasses import dataclass
21
20
  from typing import AsyncIterable, List, Union
22
21
 
23
22
  from livekit import agents, rtc
24
23
  from livekit.agents import stt, utils
25
24
 
25
+ from google.auth import default as gauth_default
26
+ from google.auth.exceptions import DefaultCredentialsError
26
27
  from google.cloud.speech_v2 import SpeechAsyncClient
27
28
  from google.cloud.speech_v2.types import cloud_speech
28
29
 
@@ -61,8 +62,8 @@ class STT(stt.STT):
61
62
  Create a new instance of Google STT.
62
63
 
63
64
  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.
65
+ from the file specified in ``credentials_file`` or via Application Default Credentials as
66
+ described in https://cloud.google.com/docs/authentication/application-default-credentials
66
67
  """
67
68
  super().__init__(
68
69
  capabilities=stt.STTCapabilities(streaming=True, interim_results=True)
@@ -73,10 +74,13 @@ class STT(stt.STT):
73
74
  self._credentials_file = credentials_file
74
75
 
75
76
  if credentials_file is None and credentials_info is None:
76
- creds = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS")
77
- if not creds:
77
+ try:
78
+ gauth_default()
79
+ except DefaultCredentialsError:
78
80
  raise ValueError(
79
- "GOOGLE_APPLICATION_CREDENTIALS must be set if no credentials is provided"
81
+ "Application default credentials must be available "
82
+ "when using Google STT without explicitly passing "
83
+ "credentials through credentials_info or credentials_file."
80
84
  )
81
85
 
82
86
  if isinstance(languages, str):
@@ -112,7 +116,12 @@ class STT(stt.STT):
112
116
  # recognizers may improve latency https://cloud.google.com/speech-to-text/v2/docs/recognizers#understand_recognizers
113
117
 
114
118
  # TODO(theomonnom): find a better way to access the project_id
115
- project_id = self._ensure_client().transport._credentials.project_id # type: ignore
119
+ try:
120
+ project_id = self._ensure_client().transport._credentials.project_id # type: ignore
121
+ except AttributeError:
122
+ from google.auth import default as ga_default
123
+
124
+ _, project_id = ga_default()
116
125
  return f"projects/{project_id}/locations/global/recognizers/_"
117
126
 
118
127
  def _sanitize_options(self, *, language: str | None = None) -> STTOptions:
@@ -141,13 +141,25 @@ class ChunkedStream(tts.ChunkedStream):
141
141
  data = response.audio_content
142
142
  if self._opts.audio_config.audio_encoding == "mp3":
143
143
  decoder = utils.codecs.Mp3StreamDecoder()
144
+ bstream = utils.audio.AudioByteStream(
145
+ sample_rate=self._opts.audio_config.sample_rate_hertz, num_channels=1
146
+ )
144
147
  for frame in decoder.decode_chunk(data):
148
+ for frame in bstream.write(frame.data):
149
+ self._event_ch.send_nowait(
150
+ tts.SynthesizedAudio(
151
+ request_id=request_id, segment_id=segment_id, frame=frame
152
+ )
153
+ )
154
+
155
+ for frame in bstream.flush():
145
156
  self._event_ch.send_nowait(
146
157
  tts.SynthesizedAudio(
147
158
  request_id=request_id, segment_id=segment_id, frame=frame
148
159
  )
149
160
  )
150
161
  else:
162
+ data = data[44:] # skip WAV header
151
163
  self._event_ch.send_nowait(
152
164
  tts.SynthesizedAudio(
153
165
  request_id=request_id,
@@ -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.3"
15
+ __version__ = "0.7.1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: livekit-plugins-google
3
- Version: 0.6.3
3
+ Version: 0.7.1
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
@@ -19,6 +19,7 @@ Classifier: Programming Language :: Python :: 3.10
19
19
  Classifier: Programming Language :: Python :: 3 :: Only
20
20
  Requires-Python: >=3.9.0
21
21
  Description-Content-Type: text/markdown
22
+ Requires-Dist: google-auth <3,>=2
22
23
  Requires-Dist: google-cloud-speech <3,>=2
23
24
  Requires-Dist: google-cloud-texttospeech <3,>=2
24
25
  Requires-Dist: livekit-agents >=0.8.0.dev0
@@ -35,4 +36,4 @@ pip install livekit-plugins-google
35
36
 
36
37
  ## Pre-requisites
37
38
 
38
- For credentials, you'll need a Google Cloud account and obtain the correct credentials. Credentials can be passed directly or set as [GOOGLE_APPLICATION_CREDENTIALS](https://cloud.google.com/docs/authentication/application-default-credentials) environment variable.
39
+ For credentials, you'll need a Google Cloud account and obtain the correct credentials. Credentials can be passed directly or via Application Default Credentials as specified in [How Application Default Credentials works](https://cloud.google.com/docs/authentication/application-default-credentials).
@@ -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=XXDOISg-8U1MzVu543xLEB3-mr_NFKJp9qo1-ya2-Hc,13569
6
+ livekit/plugins/google/tts.py,sha256=T9AHsxofwo3XaMciJPWh9O7lTZqDVYdQQlnFPiGWVbQ,6170
7
+ livekit/plugins/google/version.py,sha256=JOBYrlKcxbTTRXkUKH0921GsmV-i71_KHczg2cgQiLc,600
8
+ livekit_plugins_google-0.7.1.dist-info/METADATA,sha256=MyDLqZp1DC52KWx_Re3Hj0kO75l-Dg9z9IfiihtH4KY,1653
9
+ livekit_plugins_google-0.7.1.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
10
+ livekit_plugins_google-0.7.1.dist-info/top_level.txt,sha256=OoDok3xUmXbZRvOrfvvXB-Juu4DX79dlq188E19YHoo,8
11
+ livekit_plugins_google-0.7.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.1.0)
2
+ Generator: setuptools (75.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=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,,