-
Notifications
You must be signed in to change notification settings - Fork 3.7k
meta: add Muse Voice Transcribe STT plugin #7096
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
Open
CHVSAnirudh
wants to merge
4
commits into
livekit:main
Choose a base branch
from
CHVSAnirudh:feat/meta-muse-stt-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
503306c
meta: add Muse Voice Transcribe STT plugin
CHVSAnirudh 3ee7af7
meta: close streams on aclose, defer reconnects to turn boundaries
CHVSAnirudh cdbddba
meta: document the public STT surface
CHVSAnirudh a681d1e
meta: read the API key from META_API_KEY
CHVSAnirudh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Meta plugin for LiveKit Agents | ||
|
|
||
| Support for speech-to-text with [Meta](https://dev.meta.ai/)'s Muse Voice Transcribe. | ||
|
|
||
| See the [Meta integration docs](https://docs.livekit.io/agents/integrations/stt/meta/) for more information. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install livekit-plugins-meta | ||
| ``` | ||
|
|
||
| ## Pre-requisites | ||
|
|
||
| You'll need an API key from the Meta Model API. It can be set as an environment variable: `META_API_KEY` |
54 changes: 54 additions & 0 deletions
54
livekit-plugins/livekit-plugins-meta/livekit/plugins/meta/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Copyright 2026 LiveKit, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Meta plugin for LiveKit Agents | ||
|
|
||
| Speech-to-text with Muse Voice Transcribe. | ||
| See https://dev.meta.ai/docs/speech-to-text for more information. | ||
| """ | ||
|
|
||
| from .models import MuseEncoding, MuseMode, MuseModels, MusePartialMode | ||
| from .stt import STT, SpeechStream | ||
| from .version import __version__ | ||
|
|
||
| __all__ = [ | ||
| "STT", | ||
| "MuseEncoding", | ||
| "MuseMode", | ||
| "MuseModels", | ||
| "MusePartialMode", | ||
| "SpeechStream", | ||
| "__version__", | ||
| ] | ||
|
|
||
| from livekit.agents import Plugin | ||
|
|
||
| from .log import logger | ||
|
|
||
|
|
||
| class MetaPlugin(Plugin): | ||
| def __init__(self) -> None: | ||
| super().__init__(__name__, __version__, __package__, logger) | ||
|
|
||
|
|
||
| Plugin.register_plugin(MetaPlugin()) | ||
|
|
||
| # Cleanup docs of unexported modules | ||
| _module = dir() | ||
| NOT_IN_ALL = [m for m in _module if m not in __all__] | ||
|
|
||
| __pdoc__ = {} | ||
|
|
||
| for n in NOT_IN_ALL: | ||
| __pdoc__[n] = False |
39 changes: 39 additions & 0 deletions
39
livekit-plugins/livekit-plugins-meta/livekit/plugins/meta/_utils.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import time | ||
| from typing import TYPE_CHECKING, Generic, TypeVar | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Callable | ||
|
|
||
| T = TypeVar("T") | ||
|
|
||
|
|
||
| class PeriodicCollector(Generic[T]): | ||
| def __init__(self, callback: Callable[[T], None], *, duration: float) -> None: | ||
| """Accumulate values and hand the total to `callback` every `duration` seconds. | ||
|
|
||
| Args: | ||
| callback: Called with the accumulated total when `duration` elapses. | ||
| duration: Seconds between callback invocations. | ||
| """ | ||
| self._duration = duration | ||
| self._callback = callback | ||
| self._last_flush_time = time.monotonic() | ||
| self._total: T | None = None | ||
|
|
||
| def push(self, value: T) -> None: | ||
| """Add a value to the accumulator.""" | ||
| if self._total is None: | ||
| self._total = value | ||
| else: | ||
| self._total += value # type: ignore[operator] | ||
| if time.monotonic() - self._last_flush_time >= self._duration: | ||
| self.flush() | ||
|
|
||
| def flush(self) -> None: | ||
| """Report the current total, if any, and start a new period.""" | ||
| if self._total is not None: | ||
| self._callback(self._total) | ||
| self._total = None | ||
| self._last_flush_time = time.monotonic() |
3 changes: 3 additions & 0 deletions
3
livekit-plugins/livekit-plugins-meta/livekit/plugins/meta/log.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import logging | ||
|
|
||
| logger = logging.getLogger("livekit.plugins.meta") |
86 changes: 86 additions & 0 deletions
86
livekit-plugins/livekit-plugins-meta/livekit/plugins/meta/models.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Literal | ||
|
|
||
| from livekit.agents.language import LanguageCode | ||
|
|
||
| from .log import logger | ||
|
|
||
| MuseModels = Literal["muse-voice-transcribe-1.0"] | ||
|
|
||
| MuseEncoding = Literal["PCM_24KHZ", "PCM_16KHZ"] | ||
| """Signed 16-bit little-endian mono PCM, at 24 kHz or 16 kHz.""" | ||
|
|
||
| SAMPLE_RATES: dict[str, int] = {"PCM_24KHZ": 24000, "PCM_16KHZ": 16000} | ||
|
|
||
| MuseMode = Literal["PUSH_TO_TALK", "ENDPOINTING", "DIARIZATION"] | ||
| """PUSH_TO_TALK: the caller delimits the turn. ENDPOINTING: the model detects turn | ||
| boundaries, one turn per speech segment. DIARIZATION: adds speaker attribution.""" | ||
|
|
||
| MusePartialMode = Literal["CUMULATIVE", "DELTA"] | ||
| """CUMULATIVE: every ``transcript`` event carries the whole current hypothesis and | ||
| replaces the previous one. DELTA: per-chunk text, for the file endpoint's SSE mode.""" | ||
|
|
||
| # The 25 languages Meta lists as evaluated for muse-voice-transcribe-1.0. Muse takes | ||
| # `languageBias` as English language *names*, not BCP-47 codes, so this is keyed by the | ||
| # base code LanguageCode.language produces ("en-US" and "cmn-Hans-CN" both reduce here). | ||
| SUPPORTED_LANGUAGES: frozenset[str] = frozenset( | ||
| { | ||
| "ar", | ||
| "bn", | ||
| "de", | ||
| "en", | ||
| "es", | ||
| "fr", | ||
| "he", | ||
| "hi", | ||
| "id", | ||
| "it", | ||
| "ja", | ||
| "kn", | ||
| "ko", | ||
| "mr", | ||
| "ms", | ||
| "nl", | ||
| "pl", | ||
| "pt", | ||
| "ta", | ||
| "te", | ||
| "th", | ||
| "tl", | ||
| "tr", | ||
| "vi", | ||
| "zh", | ||
| } | ||
| ) | ||
|
|
||
| # LanguageCode.to_language_name() covers 23 of the 25 (lowercased); these two it does | ||
| # not: it calls zh "chinese" where Meta's list says "Mandarin Chinese", and it has no | ||
| # name for Filipino, which is Tagalog on Meta's side. | ||
| _LANGUAGE_NAME_OVERRIDES: dict[str, str] = {"zh": "Mandarin Chinese", "fil": "Tagalog"} | ||
|
|
||
|
|
||
| def to_language_bias(languages: list[str]) -> list[str]: | ||
| """Map BCP-47 codes onto the English language names Muse's `languageBias` expects. | ||
|
|
||
| Codes Muse does not list are dropped with a warning rather than forwarded: the | ||
| handshake is rejected wholesale on an unknown bias entry, which would take down | ||
| recognition entirely instead of merely losing the hint. | ||
| """ | ||
| names: list[str] = [] | ||
| for lang in languages: | ||
| code = LanguageCode(lang) | ||
| base = code.language | ||
| name = _LANGUAGE_NAME_OVERRIDES.get(base) | ||
| if name is None and base in SUPPORTED_LANGUAGES: | ||
| resolved = code.to_language_name() | ||
| name = resolved.title() if resolved else None | ||
| if name is None: | ||
| logger.warning( | ||
| "language is not supported by Muse Voice Transcribe, dropping from languageBias", | ||
| extra={"language": lang}, | ||
| ) | ||
| continue | ||
| if name not in names: | ||
| names.append(name) | ||
| return names | ||
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.