Module livekit.plugins.fal
Sub-modules
livekit.plugins.fal.log
livekit.plugins.fal.stt
livekit.plugins.fal.version
Classes
class WizperSTT (*, language: NotGivenOr[str] = NOT_GIVEN, api_key: NotGivenOr[str] = NOT_GIVEN)
-
Expand source code
class WizperSTT(stt.STT): def __init__( self, *, language: NotGivenOr[str] = NOT_GIVEN, api_key: NotGivenOr[str] = NOT_GIVEN, ): super().__init__(capabilities=STTCapabilities(streaming=False, interim_results=True)) self._api_key = api_key if is_given(api_key) else os.getenv("FAL_KEY") if not self._api_key: raise ValueError("fal AI API key is required. It should be set with env FAL_KEY") self._opts = _STTOptions(language=language) self._fal_client = fal_client.AsyncClient(key=self._api_key) def update_options(self, *, language: NotGivenOr[str] = NOT_GIVEN) -> None: if is_given(language): self._opts.language = language async def _recognize_impl( self, buffer: AudioBuffer, *, language: NotGivenOr[str] = NOT_GIVEN, conn_options: APIConnectOptions, ) -> stt.SpeechEvent: try: if is_given(language): self._opts.language = language data_uri = fal_client.encode( rtc.combine_audio_frames(buffer).to_wav_bytes(), "audio/x-wav" ) response = await self._fal_client.run( "fal-ai/wizper", arguments={ "audio_url": data_uri, "task": self._opts.task, "language": self._opts.language, "chunk_level": self._opts.chunk_level, "version": self._opts.version, }, timeout=conn_options.timeout, ) text = response.get("text", "") return self._transcription_to_speech_event(text=text) except fal_client.client.FalClientError as e: raise APIConnectionError() from e def _transcription_to_speech_event(self, text: str) -> stt.SpeechEvent: return stt.SpeechEvent( type=SpeechEventType.FINAL_TRANSCRIPT, alternatives=[stt.SpeechData(text=text, language=self._opts.language)], ) async def aclose(self) -> None: await self._fal_client._client.aclose()
Helper class that provides a standard way to create an ABC using inheritance.
Ancestors
- livekit.agents.stt.stt.STT
- abc.ABC
- EventEmitter
- typing.Generic
Methods
async def aclose(self) ‑> None
-
Expand source code
async def aclose(self) -> None: await self._fal_client._client.aclose()
Close the STT, and every stream/requests associated with it
def update_options(self, *, language: NotGivenOr[str] = NOT_GIVEN) ‑> None
-
Expand source code
def update_options(self, *, language: NotGivenOr[str] = NOT_GIVEN) -> None: if is_given(language): self._opts.language = language
Inherited members