livekit-plugins-fal 1.0.0.dev5__py3-none-any.whl → 1.0.0rc2__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.

Potentially problematic release.


This version of livekit-plugins-fal might be problematic. Click here for more details.

@@ -1,6 +1,5 @@
1
1
  from __future__ import annotations
2
2
 
3
- import dataclasses
4
3
  import os
5
4
  from dataclasses import dataclass
6
5
 
@@ -9,66 +8,49 @@ import fal_client
9
8
  from livekit import rtc
10
9
  from livekit.agents import APIConnectionError, APIConnectOptions, stt
11
10
  from livekit.agents.stt import SpeechEventType, STTCapabilities
12
- from livekit.agents.utils import AudioBuffer
11
+ from livekit.agents.types import (
12
+ NOT_GIVEN,
13
+ NotGivenOr,
14
+ )
15
+ from livekit.agents.utils import AudioBuffer, is_given
13
16
 
14
17
 
15
18
  @dataclass
16
19
  class _STTOptions:
17
- language: str
18
- task: str
19
- chunk_level: str
20
- version: str
20
+ language: str = "en"
21
+ task: str = "transcribe"
22
+ chunk_level: str = "segment"
23
+ version: str = "3"
21
24
 
22
25
 
23
26
  class WizperSTT(stt.STT):
24
27
  def __init__(
25
28
  self,
26
29
  *,
27
- language: str | None = "en",
28
- task: str | None = "transcribe",
29
- chunk_level: str | None = "segment",
30
- version: str | None = "3",
30
+ language: NotGivenOr[str] = NOT_GIVEN,
31
+ api_key: NotGivenOr[str] = NOT_GIVEN,
31
32
  ):
32
33
  super().__init__(capabilities=STTCapabilities(streaming=False, interim_results=True))
33
- self._api_key = os.getenv("FAL_KEY")
34
- self._opts = _STTOptions(
35
- language=language or "en",
36
- task=task or "transcribe",
37
- chunk_level=chunk_level or "segment",
38
- version=version or "3",
39
- )
40
- self._fal_client = fal_client.AsyncClient()
41
-
34
+ self._api_key = api_key if is_given(api_key) else os.getenv("FAL_KEY")
42
35
  if not self._api_key:
43
36
  raise ValueError("fal AI API key is required. It should be set with env FAL_KEY")
37
+ self._opts = _STTOptions(language=language)
38
+ self._fal_client = fal_client.AsyncClient(key=self._api_key)
44
39
 
45
- def update_options(self, *, language: str | None = None) -> None:
46
- self._opts.language = language or self._opts.language
47
-
48
- def _sanitize_options(
49
- self,
50
- *,
51
- language: str | None = None,
52
- task: str | None = None,
53
- chunk_level: str | None = None,
54
- version: str | None = None,
55
- ) -> _STTOptions:
56
- config = dataclasses.replace(self._opts)
57
- config.language = language or config.language
58
- config.task = task or config.task
59
- config.chunk_level = chunk_level or config.chunk_level
60
- config.version = version or config.version
61
- return config
40
+ def update_options(self, *, language: NotGivenOr[str] = NOT_GIVEN) -> None:
41
+ if is_given(language):
42
+ self._opts.language = language
62
43
 
63
44
  async def _recognize_impl(
64
45
  self,
65
46
  buffer: AudioBuffer,
66
47
  *,
67
- language: str | None,
48
+ language: NotGivenOr[str] = NOT_GIVEN,
68
49
  conn_options: APIConnectOptions,
69
50
  ) -> stt.SpeechEvent:
70
51
  try:
71
- config = self._sanitize_options(language=language)
52
+ if is_given(language):
53
+ self._opts.language = language
72
54
  data_uri = fal_client.encode(
73
55
  rtc.combine_audio_frames(buffer).to_wav_bytes(), "audio/x-wav"
74
56
  )
@@ -76,10 +58,10 @@ class WizperSTT(stt.STT):
76
58
  "fal-ai/wizper",
77
59
  arguments={
78
60
  "audio_url": data_uri,
79
- "task": config.task,
80
- "language": config.language,
81
- "chunk_level": config.chunk_level,
82
- "version": config.version,
61
+ "task": self._opts.task,
62
+ "language": self._opts.language,
63
+ "chunk_level": self._opts.chunk_level,
64
+ "version": self._opts.version,
83
65
  },
84
66
  timeout=conn_options.timeout,
85
67
  )
@@ -88,11 +70,9 @@ class WizperSTT(stt.STT):
88
70
  except fal_client.client.FalClientError as e:
89
71
  raise APIConnectionError() from e
90
72
 
91
- def _transcription_to_speech_event(
92
- self, event_type=SpeechEventType.FINAL_TRANSCRIPT, text=None
93
- ) -> stt.SpeechEvent:
73
+ def _transcription_to_speech_event(self, text: str) -> stt.SpeechEvent:
94
74
  return stt.SpeechEvent(
95
- type=event_type,
75
+ type=SpeechEventType.FINAL_TRANSCRIPT,
96
76
  alternatives=[stt.SpeechData(text=text, language=self._opts.language)],
97
77
  )
98
78
 
@@ -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__ = "1.0.0.dev5"
15
+ __version__ = '1.0.0.rc2'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: livekit-plugins-fal
3
- Version: 1.0.0.dev5
3
+ Version: 1.0.0rc2
4
4
  Summary: fal plugin template for LiveKit Agents
5
5
  Project-URL: Documentation, https://docs.livekit.io
6
6
  Project-URL: Website, https://livekit.io/
@@ -19,7 +19,7 @@ Classifier: Topic :: Multimedia :: Video
19
19
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
20
  Requires-Python: >=3.9.0
21
21
  Requires-Dist: fal-client
22
- Requires-Dist: livekit-agents>=1.0.0.dev5
22
+ Requires-Dist: livekit-agents>=1.0.0.rc2
23
23
  Description-Content-Type: text/markdown
24
24
 
25
25
  # LiveKit Plugins fal
@@ -0,0 +1,8 @@
1
+ livekit/plugins/fal/__init__.py,sha256=2yFGbnRBL846WEDry3a4CTTwWSiLSI4Otqhlo6g4Lf4,1476
2
+ livekit/plugins/fal/log.py,sha256=E03cKaUVgXY2O7RpX33IQIaRCpFJ_nJMSkRCvCxX5fc,66
3
+ livekit/plugins/fal/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ livekit/plugins/fal/stt.py,sha256=i7kWKvftNbOZFaJzsrTz3gcO06m1dUnfQaWG8vAGSBo,2688
5
+ livekit/plugins/fal/version.py,sha256=9dPToS7uQhNVGiqP6fLx_l0Akub-11rRUoyDaiS4_CU,603
6
+ livekit_plugins_fal-1.0.0rc2.dist-info/METADATA,sha256=fr1nbE2tmZA8MMtz191NrEyvVI9pi-PhrIY9DLEGDj4,1286
7
+ livekit_plugins_fal-1.0.0rc2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ livekit_plugins_fal-1.0.0rc2.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- livekit/plugins/fal/__init__.py,sha256=2yFGbnRBL846WEDry3a4CTTwWSiLSI4Otqhlo6g4Lf4,1476
2
- livekit/plugins/fal/log.py,sha256=E03cKaUVgXY2O7RpX33IQIaRCpFJ_nJMSkRCvCxX5fc,66
3
- livekit/plugins/fal/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- livekit/plugins/fal/stt.py,sha256=PsLrehk5tunahzxAzOFA1OmpBHuV72ESCZE4MoqKCAw,3225
5
- livekit/plugins/fal/version.py,sha256=_S-ahwrVT8tkQeIdVxA-cTboUyLFxWwbotIZ6BTvw6E,604
6
- livekit_plugins_fal-1.0.0.dev5.dist-info/METADATA,sha256=Hb3vG82vMBctBao94XtlmUFUPvj8OlOoph3TgMdWr4s,1289
7
- livekit_plugins_fal-1.0.0.dev5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
- livekit_plugins_fal-1.0.0.dev5.dist-info/RECORD,,