livekit-plugins-fal 0.2.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.

Potentially problematic release.


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

@@ -0,0 +1,46 @@
1
+ # Copyright 2023 LiveKit, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Copyright 2023 LiveKit, Inc.
16
+ #
17
+ # Licensed under the Apache License, Version 2.0 (the "License");
18
+ # you may not use this file except in compliance with the License.
19
+ # You may obtain a copy of the License at
20
+ #
21
+ # http://www.apache.org/licenses/LICENSE-2.0
22
+ #
23
+ # Unless required by applicable law or agreed to in writing, software
24
+ # distributed under the License is distributed on an "AS IS" BASIS,
25
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
+ # See the License for the specific language governing permissions and
27
+ # limitations under the License.
28
+
29
+
30
+ from .stt import WizperSTT
31
+ from .version import __version__
32
+
33
+ __all__ = ["WizperSTT", "__version__"]
34
+
35
+
36
+ from livekit.agents import Plugin
37
+
38
+ from .log import logger
39
+
40
+
41
+ class FalPlugin(Plugin):
42
+ def __init__(self):
43
+ super().__init__(__name__, __version__, __package__, logger)
44
+
45
+
46
+ Plugin.register_plugin(FalPlugin())
@@ -0,0 +1,3 @@
1
+ import logging
2
+
3
+ logger = logging.getLogger("livekit.plugins.fal")
File without changes
@@ -0,0 +1,108 @@
1
+ from __future__ import annotations
2
+
3
+ import dataclasses
4
+ import os
5
+ from dataclasses import dataclass
6
+ from typing import Optional
7
+
8
+ import fal_client
9
+ from livekit import rtc
10
+ from livekit.agents import (
11
+ APIConnectionError,
12
+ APIConnectOptions,
13
+ stt,
14
+ )
15
+ from livekit.agents.stt import SpeechEventType, STTCapabilities
16
+ from livekit.agents.utils import AudioBuffer
17
+
18
+
19
+ @dataclass
20
+ class _STTOptions:
21
+ language: str
22
+ task: str
23
+ chunk_level: str
24
+ version: str
25
+
26
+
27
+ class WizperSTT(stt.STT):
28
+ def __init__(
29
+ self,
30
+ *,
31
+ language: Optional[str] = "en",
32
+ task: Optional[str] = "transcribe",
33
+ chunk_level: Optional[str] = "segment",
34
+ version: Optional[str] = "3",
35
+ ):
36
+ super().__init__(
37
+ capabilities=STTCapabilities(streaming=False, interim_results=True)
38
+ )
39
+ self._api_key = os.getenv("FAL_KEY")
40
+ self._opts = _STTOptions(
41
+ language=language or "en",
42
+ task=task or "transcribe",
43
+ chunk_level=chunk_level or "segment",
44
+ version=version or "3",
45
+ )
46
+ self._fal_client = fal_client.AsyncClient()
47
+
48
+ if not self._api_key:
49
+ raise ValueError(
50
+ "FAL AI API key is required. It should be set with env FAL_KEY"
51
+ )
52
+
53
+ def update_options(self, *, language: Optional[str] = None) -> None:
54
+ self._opts.language = language or self._opts.language
55
+
56
+ def _sanitize_options(
57
+ self,
58
+ *,
59
+ language: Optional[str] = None,
60
+ task: Optional[str] = None,
61
+ chunk_level: Optional[str] = None,
62
+ version: Optional[str] = None,
63
+ ) -> _STTOptions:
64
+ config = dataclasses.replace(self._opts)
65
+ config.language = language or config.language
66
+ config.task = task or config.task
67
+ config.chunk_level = chunk_level or config.chunk_level
68
+ config.version = version or config.version
69
+ return config
70
+
71
+ async def _recognize_impl(
72
+ self,
73
+ buffer: AudioBuffer,
74
+ *,
75
+ language: str | None,
76
+ conn_options: APIConnectOptions,
77
+ ) -> stt.SpeechEvent:
78
+ try:
79
+ config = self._sanitize_options(language=language)
80
+ data_uri = fal_client.encode(
81
+ rtc.combine_audio_frames(buffer).to_wav_bytes(), "audio/x-wav"
82
+ )
83
+ response = await self._fal_client.run(
84
+ "fal-ai/wizper",
85
+ arguments={
86
+ "audio_url": data_uri,
87
+ "task": config.task,
88
+ "language": config.language,
89
+ "chunk_level": config.chunk_level,
90
+ "version": config.version,
91
+ },
92
+ timeout=conn_options.timeout,
93
+ )
94
+ text = response.get("text", "")
95
+ return self._transcription_to_speech_event(text=text)
96
+ except fal_client.client.FalClientError as e:
97
+ raise APIConnectionError() from e
98
+
99
+ def _transcription_to_speech_event(
100
+ self, event_type=SpeechEventType.FINAL_TRANSCRIPT, text=None
101
+ ) -> stt.SpeechEvent:
102
+ return stt.SpeechEvent(
103
+ type=event_type,
104
+ alternatives=[stt.SpeechData(text=text, language=self._opts.language)],
105
+ )
106
+
107
+ async def aclose(self) -> None:
108
+ await self._fal_client._client.aclose()
@@ -0,0 +1,15 @@
1
+ # Copyright 2023 LiveKit, Inc.
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ __version__ = "0.2.3"
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.2
2
+ Name: livekit-plugins-fal
3
+ Version: 0.2.3
4
+ Summary: fal plugin template for LiveKit Agents
5
+ Home-page: https://github.com/livekit/agents
6
+ License: Apache-2.0
7
+ Project-URL: Documentation, https://docs.livekit.io
8
+ Project-URL: Website, https://livekit.io/
9
+ Project-URL: Source, https://github.com/livekit/agents
10
+ Keywords: webrtc,realtime,audio,video,livekit
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Topic :: Multimedia :: Sound/Audio
14
+ Classifier: Topic :: Multimedia :: Video
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Requires-Python: >=3.9.0
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: livekit-agents>=0.12.3
23
+ Requires-Dist: fal_client
24
+ Dynamic: classifier
25
+ Dynamic: description
26
+ Dynamic: description-content-type
27
+ Dynamic: home-page
28
+ Dynamic: keywords
29
+ Dynamic: license
30
+ Dynamic: project-url
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
34
+
35
+ # LiveKit Plugins Fal
36
+
37
+ This plugin provides a simple way to integrate FAL models into the LiveKit Agent Framework. currently supports Whizper model for STT
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ pip install livekit-plugins-fal
43
+ ```
44
+
45
+ ## Pre-requisites
46
+
47
+ You'll need an API key from FAL. It can be set as an environment variable: `FAL_KEY`
@@ -0,0 +1,9 @@
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=HGOX_E-W6MCpefQFGj_UPw8X9gvsmoVLAO65FAz6-Es,3348
5
+ livekit/plugins/fal/version.py,sha256=hlkazOSjHhPITxXYBxVrCPGHhRf5IltBTWpXAL6jTfw,599
6
+ livekit_plugins_fal-0.2.3.dist-info/METADATA,sha256=Gu-XJuqmc0C1MKfsWvlvZGx9wmCj8rJRRLGKPbpvNpc,1510
7
+ livekit_plugins_fal-0.2.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
+ livekit_plugins_fal-0.2.3.dist-info/top_level.txt,sha256=OoDok3xUmXbZRvOrfvvXB-Juu4DX79dlq188E19YHoo,8
9
+ livekit_plugins_fal-0.2.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.8.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ livekit