Module livekit.plugins.telnyx
Sub-modules
livekit.plugins.telnyx.commonlivekit.plugins.telnyx.loglivekit.plugins.telnyx.stt-
- Telnyx STT API documentation: https://developers.telnyx.com/docs/voice/programmable-voice/stt-standalone.
livekit.plugins.telnyx.tts-
- Telnyx TTS API documentation: https://developers.telnyx.com/docs/voice/programmable-voice/tts-standalone.
livekit.plugins.telnyx.version
Classes
class STT (*,
language: str = 'en',
transcription_engine: TranscriptionEngine = 'telnyx',
interim_results: bool = True,
api_key: str | None = None,
base_url: str = 'wss://api.telnyx.com/v2/speech-to-text/transcription',
sample_rate: int = 16000,
http_session: aiohttp.ClientSession | None = None)-
Expand source code
class STT(stt.STT): def __init__( self, *, language: str = "en", transcription_engine: TranscriptionEngine = "telnyx", interim_results: bool = True, api_key: str | None = None, base_url: str = STT_ENDPOINT, sample_rate: int = SAMPLE_RATE, http_session: aiohttp.ClientSession | None = None, ) -> None: super().__init__( capabilities=stt.STTCapabilities( streaming=True, interim_results=interim_results, ) ) self._opts = _STTOptions( api_key=get_api_key(api_key), language=LanguageCode(language), transcription_engine=transcription_engine, interim_results=interim_results, base_url=base_url, sample_rate=sample_rate, ) self._session_manager = SessionManager(http_session) self._streams = weakref.WeakSet[SpeechStream]() @property def model(self) -> str: return self._opts.transcription_engine @property def provider(self) -> str: return "telnyx" async def _recognize_impl( self, buffer: AudioBuffer, *, language: NotGivenOr[str] = NOT_GIVEN, conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS, ) -> stt.SpeechEvent: resolved_language = LanguageCode(language) if is_given(language) else self._opts.language stream = self.stream(language=language, conn_options=conn_options) try: frames = buffer if isinstance(buffer, list) else [buffer] for frame in frames: stream.push_frame(frame) stream.end_input() final_text = "" async for event in stream: if event.type == stt.SpeechEventType.FINAL_TRANSCRIPT: if event.alternatives: final_text += event.alternatives[0].text return stt.SpeechEvent( type=stt.SpeechEventType.FINAL_TRANSCRIPT, alternatives=[ stt.SpeechData( language=resolved_language, text=final_text, ) ], ) finally: await stream.aclose() def stream( self, *, language: NotGivenOr[str] = NOT_GIVEN, conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS, ) -> SpeechStream: resolved_language = LanguageCode(language) if is_given(language) else self._opts.language stream = SpeechStream( stt=self, conn_options=conn_options, language=resolved_language, ) self._streams.add(stream) return stream async def aclose(self) -> None: for stream in list(self._streams): await stream.aclose() self._streams.clear() await self._session_manager.close()Helper class that provides a standard way to create an ABC using inheritance.
Ancestors
- livekit.agents.stt.stt.STT
- abc.ABC
- EventEmitter
- typing.Generic
Instance variables
prop model : str-
Expand source code
@property def model(self) -> str: return self._opts.transcription_engineGet the model name/identifier for this STT instance.
Returns
The model name if available, "unknown" otherwise.
Note
Plugins should override this property to provide their model information.
prop provider : str-
Expand source code
@property def provider(self) -> str: return "telnyx"Get the provider name/identifier for this STT instance.
Returns
The provider name if available, "unknown" otherwise.
Note
Plugins should override this property to provide their provider information.
Methods
async def aclose(self) ‑> None-
Expand source code
async def aclose(self) -> None: for stream in list(self._streams): await stream.aclose() self._streams.clear() await self._session_manager.close()Close the STT, and every stream/requests associated with it
def stream(self,
*,
language: NotGivenOr[str] = NOT_GIVEN,
conn_options: APIConnectOptions = APIConnectOptions(max_retry=3, retry_interval=2.0, timeout=10.0)) ‑> SpeechStream-
Expand source code
def stream( self, *, language: NotGivenOr[str] = NOT_GIVEN, conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS, ) -> SpeechStream: resolved_language = LanguageCode(language) if is_given(language) else self._opts.language stream = SpeechStream( stt=self, conn_options=conn_options, language=resolved_language, ) self._streams.add(stream) return stream
Inherited members
class TTS (*,
voice: str = 'Telnyx.NaturalHD.astra',
api_key: str | None = None,
base_url: str = 'wss://api.telnyx.com/v2/text-to-speech/speech',
http_session: aiohttp.ClientSession | None = None)-
Expand source code
class TTS(tts.TTS): def __init__( self, *, voice: str = "Telnyx.NaturalHD.astra", api_key: str | None = None, base_url: str = TTS_ENDPOINT, http_session: aiohttp.ClientSession | None = None, ) -> None: super().__init__( capabilities=tts.TTSCapabilities(streaming=True), sample_rate=SAMPLE_RATE, num_channels=NUM_CHANNELS, ) self._opts = _TTSOptions( voice=voice, api_key=get_api_key(api_key), base_url=base_url, ) self._session_manager = SessionManager(http_session) self._streams = weakref.WeakSet[SynthesizeStream]() @property def model(self) -> str: return self._opts.voice @property def provider(self) -> str: return "telnyx" def synthesize( self, text: str, *, conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS, ) -> tts.ChunkedStream: return self._synthesize_with_stream(text, conn_options=conn_options) def stream( self, *, conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS ) -> SynthesizeStream: stream = SynthesizeStream(tts=self, conn_options=conn_options) self._streams.add(stream) return stream async def aclose(self) -> None: for stream in list(self._streams): await stream.aclose() self._streams.clear() await self._session_manager.close()Helper class that provides a standard way to create an ABC using inheritance.
Ancestors
- livekit.agents.tts.tts.TTS
- abc.ABC
- EventEmitter
- typing.Generic
Instance variables
prop model : str-
Expand source code
@property def model(self) -> str: return self._opts.voiceGet the model name/identifier for this TTS instance.
Returns
The model name if available, "unknown" otherwise.
Note
Plugins should override this property to provide their model information.
prop provider : str-
Expand source code
@property def provider(self) -> str: return "telnyx"Get the provider name/identifier for this TTS instance.
Returns
The provider name if available, "unknown" otherwise.
Note
Plugins should override this property to provide their provider information.
Methods
async def aclose(self) ‑> None-
Expand source code
async def aclose(self) -> None: for stream in list(self._streams): await stream.aclose() self._streams.clear() await self._session_manager.close() def stream(self,
*,
conn_options: APIConnectOptions = APIConnectOptions(max_retry=3, retry_interval=2.0, timeout=10.0)) ‑> SynthesizeStream-
Expand source code
def stream( self, *, conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS ) -> SynthesizeStream: stream = SynthesizeStream(tts=self, conn_options=conn_options) self._streams.add(stream) return stream def synthesize(self,
text: str,
*,
conn_options: APIConnectOptions = APIConnectOptions(max_retry=3, retry_interval=2.0, timeout=10.0)) ‑> livekit.agents.tts.tts.ChunkedStream-
Expand source code
def synthesize( self, text: str, *, conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS, ) -> tts.ChunkedStream: return self._synthesize_with_stream(text, conn_options=conn_options)
Inherited members