Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatically create stt.StreamAdapter when provided stt doesn't support streaming #536

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fluffy-terms-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-agents": patch
---

automatically create stt.StreamAdapter when provided stt doesn't support streaming
4 changes: 2 additions & 2 deletions examples/voice-assistant/minimal_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from livekit.agents import AutoSubscribe, JobContext, WorkerOptions, cli, llm
from livekit.agents.voice_assistant import VoiceAssistant
from livekit.plugins import deepgram, elevenlabs, openai, silero
from livekit.plugins import deepgram, openai, silero


async def entrypoint(ctx: JobContext):
Expand All @@ -20,7 +20,7 @@ async def entrypoint(ctx: JobContext):
vad=silero.VAD.load(),
stt=deepgram.STT(),
llm=openai.LLM(),
tts=elevenlabs.TTS(),
tts=openai.TTS(),
chat_ctx=initial_ctx,
)
assistant.start(ctx.room)
Expand Down
1 change: 0 additions & 1 deletion examples/voice-assistant/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
livekit-agents~=0.7.2
livekit-plugins-openai~=0.6
livekit-plugins-deepgram~=0.5
livekit-plugins-elevenlabs~=0.6
livekit-plugins-silero~=0.5

3 changes: 1 addition & 2 deletions livekit-agents/livekit/agents/stt/stt.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ async def recognize(

def stream(self, *, language: str | None = None) -> "SpeechStream":
raise NotImplementedError(
"streaming is not supported by this STT, please use \
a different STT or use a StreamAdapter"
"streaming is not supported by this STT, please use a different STT or use a StreamAdapter"
)

async def aclose(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,22 @@ def __init__(

# wrap with StreamAdapter automatically when streaming is not supported on a specific TTS
# to override StreamAdapter options, create the adapter manually

if not tts.capabilities.streaming:
from .. import tts as text_to_speech

tts = text_to_speech.StreamAdapter(
tts=tts, sentence_tokenizer=tokenize.basic.SentenceTokenizer()
)

if not stt.capabilities.streaming:
from .. import stt as speech_to_text

stt = speech_to_text.StreamAdapter(
stt=stt,
vad=vad,
)

self._stt, self._vad, self._llm, self._tts = stt, vad, llm, tts
self._chat_ctx = chat_ctx or ChatContext()
self._fnc_ctx = fnc_ctx
Expand Down
Loading