diff --git a/.changeset/eleven-items-love.md b/.changeset/eleven-items-love.md new file mode 100644 index 000000000..37b3cf6b4 --- /dev/null +++ b/.changeset/eleven-items-love.md @@ -0,0 +1,5 @@ +--- +"livekit-plugins-openai": patch +--- + +Groq integration with Whisper-compatible STT endpoints diff --git a/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/models.py b/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/models.py index 092684519..c655f6662 100644 --- a/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/models.py +++ b/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/models.py @@ -70,6 +70,12 @@ "gemma2-9b-it", ] +GroqAudioModels = Literal[ + "whisper-large-v3", + "distil-whisper-large-v3-en", + "whisper-large-v3-turbo" +] + DeepSeekChatModels = Literal[ "deepseek-coder", "deepseek-chat", diff --git a/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/stt.py b/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/stt.py index be36817d9..480117c78 100644 --- a/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/stt.py +++ b/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/stt.py @@ -16,6 +16,7 @@ import dataclasses import io +import os import wave from dataclasses import dataclass @@ -26,7 +27,7 @@ import openai -from .models import WhisperModels +from .models import WhisperModels, GroqAudioModels @dataclass @@ -80,6 +81,39 @@ def __init__( ), ) + + @staticmethod + def with_groq( + *, + model: GroqAudioModels = "whisper-large-v3-turbo", + api_key: str | None = None, + base_url: str | None = "https://api.groq.com/openai/v1", + client: openai.AsyncClient | None = None, + language: str = "en", + detect_language: bool = False, + ) -> STT: + """ + Create a new instance of Groq STT. + + ``api_key`` must be set to your Groq API key, either using the argument or by setting + the ``GROQ_API_KEY`` environmental variable. + """ + + # Use environment variable if API key is not provided + api_key = api_key or os.environ.get("GROQ_API_KEY") + if api_key is None: + raise ValueError("Groq API key is required") + + # Instantiate and return a configured STT instance + return STT( + model=model, + api_key=api_key, + base_url=base_url, + client=client, + language=language, + detect_language=detect_language, + ) + def _sanitize_options(self, *, language: str | None = None) -> _STTOptions: config = dataclasses.replace(self._opts) config.language = language or config.language