forked from livekit/agents
-
Notifications
You must be signed in to change notification settings - Fork 0
Add respeecher tts plugin #1
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
mitrushchienkova
wants to merge
17
commits into
main
Choose a base branch
from
add-respeecher-TTS-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
17 commits
Select commit
Hold shift + click to select a range
65267e8
Add Respeecher TTS plugin
mitrushchienkova 3409bb5
Format code with ruff
mitrushchienkova 3cfb2ab
Apply code review suggetions
mitrushchienkova 7b72aba
Add sentence tokenizetion
mitrushchienkova 3c64512
Define sample_rate as integer instead of list of allowed values
mitrushchienkova 78d8006
Move version from model to base URL
mitrushchienkova d82e18d
Apply review suggestions
mitrushchienkova 614b6c8
Fix ruff formatting
mitrushchienkova 2b09286
Make Voice a dictionary and update timeout logic for tests
mitrushchienkova cc93c16
Reuse websocket connection across different requests
mitrushchienkova ddbdaba
Reset uv.lock changes
mitrushchienkova d7c1455
Merge remote-tracking branch 'origin/main' into add-respeecher-TTS-pl…
mitrushchienkova f1882d2
Run mypy to type checks
mitrushchienkova 742b7dd
Remove pcm_f32le
mitrushchienkova 3fd1646
Simplify string replace
mitrushchienkova b344a0e
Run ruff formatter
mitrushchienkova 80047b2
Reset uv.lock
mitrushchienkova 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
| @@ -1,3 +1,30 @@ | ||
| # Text-to-speech | ||
| # Text-to-Speech Examples | ||
|
|
||
| This small example shows how you can generate real-time audio data from text. | ||
| These examples demonstrate real-time text-to-speech generation using various TTS plugins with LiveKit. | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| ### Plugin API Keys | ||
| Set the API key for your chosen plugin. | ||
|
|
||
| ### LiveKit Connection | ||
| For connecting to LiveKit Cloud: | ||
| - `LIVEKIT_URL` - Your LiveKit server URL | ||
| - `LIVEKIT_API_KEY` - LiveKit API key | ||
| - `LIVEKIT_API_SECRET` - LiveKit API secret | ||
|
|
||
| ## Running Examples | ||
|
|
||
| Execute the example to connect to a LiveKit room and stream TTS audio: | ||
|
|
||
| ```bash | ||
| uv run examples/other/text-to-speech/{your_plugin}_tts.py start | ||
| ``` | ||
|
|
||
| The agent will join the room and stream synthesized speech to participants. | ||
|
|
||
| ### Running Locally | ||
|
|
||
| Running the examples with `console` mode won't play audio since the examples use `rtc.LocalAudioTrack`, which requires the LiveKit room infrastructure for audio playback. The `LocalAudioTrack` is designed to publish audio streams to LiveKit rooms where they are processed and distributed to participants. Without a room connection, the audio frames are generated but not routed to any playback device. | ||
|
|
||
| To test TTS output locally without a LiveKit room, you would need to modify the example file to save the generated audio frames to a WAV file instead of publishing them to a track. The saved WAV file can then be played using any audio player on your system. |
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
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,57 @@ | ||
| import asyncio | ||
| import logging | ||
|
|
||
| from dotenv import load_dotenv | ||
|
|
||
| from livekit import rtc | ||
| from livekit.agents import AutoSubscribe, JobContext, WorkerOptions, cli | ||
| from livekit.plugins import respeecher | ||
|
|
||
| load_dotenv() | ||
|
|
||
| logger = logging.getLogger("respeecher-tts-demo") | ||
| logger.setLevel(logging.INFO) | ||
|
|
||
|
|
||
| async def entrypoint(job: JobContext): | ||
| logger.info("starting tts example agent") | ||
|
|
||
| tts = respeecher.TTS() | ||
|
|
||
| source = rtc.AudioSource(tts.sample_rate, tts.num_channels) | ||
| track = rtc.LocalAudioTrack.create_audio_track("agent-mic", source) | ||
| options = rtc.TrackPublishOptions() | ||
| options.source = rtc.TrackSource.SOURCE_MICROPHONE | ||
|
|
||
| await job.connect(auto_subscribe=AutoSubscribe.SUBSCRIBE_NONE) | ||
| publication = await job.room.local_participant.publish_track(track, options) | ||
| await publication.wait_for_subscription() | ||
|
|
||
| async with tts.stream() as stream: | ||
|
|
||
| async def _playback_task(): | ||
| count = 0 | ||
| async for audio in stream: | ||
| count += 1 | ||
| await source.capture_frame(audio.frame) | ||
|
|
||
| task = asyncio.create_task(_playback_task()) | ||
|
|
||
| text = "Hello from Respeecher! I hope you are having a great day." | ||
|
|
||
| # split into two word chunks to simulate LLM streaming | ||
| words = text.split() | ||
| for i in range(0, len(words), 2): | ||
| chunk = " ".join(words[i : i + 2]) | ||
| if chunk: | ||
| logger.info(f'pushing chunk: "{chunk} "') | ||
| stream.push_text(chunk + " ") | ||
|
|
||
| # Mark end of input segment | ||
| stream.flush() | ||
| stream.end_input() | ||
| await asyncio.gather(task) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint)) |
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,27 @@ | ||
| # Respeecher plugin for LiveKit Agents | ||
|
|
||
| Support for [Respeecher](https://respeecher.com/)'s TTS in LiveKit Agents. | ||
|
|
||
| More information is available in the docs for the [Respeecher](https://docs.livekit.io/agents/integrations/tts/respeecher/) integration. | ||
mitrushchienkova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install livekit-plugins-respeecher | ||
| ``` | ||
|
|
||
| ## Pre-requisites | ||
|
|
||
| You'll need an API key from Respeecher. It can be set as an environment variable: `RESPEECHER_API_KEY` or passed to the `respeecher.TTS()` constructor. | ||
|
|
||
| To get the key, log in to [Respeecher Space](https://space.respeecher.com/). | ||
|
|
||
| ## Example | ||
|
|
||
| To try out the Respeecher plugin, run the example: | ||
|
|
||
| ```bash | ||
| uv run python examples/other/text-to-speech/respeecher_tts.py start | ||
| ``` | ||
|
|
||
| Check [`examples/other/text-to-speech/README.md`](../../examples/other/text-to-speech/README.md) for running details. | ||
44 changes: 44 additions & 0 deletions
44
livekit-plugins/livekit-plugins-respeecher/livekit/plugins/respeecher/__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,44 @@ | ||
| # Copyright 2025 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. | ||
|
|
||
| """Respeecher plugin for LiveKit Agents | ||
|
|
||
| Voice cloning and synthesis plugin for LiveKit Agents using Respeecher API. | ||
| """ | ||
|
|
||
| from .tts import TTS, ChunkedStream | ||
| from .version import __version__ | ||
|
|
||
| __all__ = ["TTS", "ChunkedStream", "__version__"] | ||
|
|
||
| from livekit.agents import Plugin | ||
|
|
||
| from .log import logger | ||
|
|
||
|
|
||
| class RespeecherPlugin(Plugin): | ||
| def __init__(self) -> None: | ||
| super().__init__(__name__, __version__, __package__, logger) | ||
|
|
||
|
|
||
| Plugin.register_plugin(RespeecherPlugin()) | ||
|
|
||
| # 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 |
3 changes: 3 additions & 0 deletions
3
livekit-plugins/livekit-plugins-respeecher/livekit/plugins/respeecher/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.respeecher") |
37 changes: 37 additions & 0 deletions
37
livekit-plugins/livekit-plugins-respeecher/livekit/plugins/respeecher/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,37 @@ | ||
| from dataclasses import dataclass | ||
| from typing import Any, Literal, Optional | ||
|
|
||
| TTSModels = Literal[ | ||
| # Respeecher's English model, multilanguage models will be added later | ||
| "/public/tts/en-rt", | ||
| ] | ||
|
|
||
| TTSEncoding = Literal["pcm_s16le",] | ||
|
|
||
|
|
||
mitrushchienkova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Check https://space.respeecher.com/docs/api/tts/sampling-params-guide for details""" | ||
| SamplingParams = dict[str, Any] | ||
|
|
||
|
|
||
| @dataclass | ||
| class VoiceSettings: | ||
| """Voice settings for Respeecher TTS""" | ||
|
|
||
| sampling_params: Optional[SamplingParams] = None | ||
|
|
||
|
|
||
| class Voice(dict): | ||
| """Voice model for Respeecher - behaves like a dict with guaranteed `id` and optional `sampling_params`""" | ||
|
|
||
| def __init__(self, *args: Any, **kwargs: Any) -> None: | ||
| super().__init__(*args, **kwargs) | ||
| if "id" not in self: | ||
| raise ValueError("Voice must have an 'id' field") | ||
|
|
||
| @property | ||
| def id(self) -> str: | ||
| return str(self["id"]) | ||
|
|
||
| @property | ||
| def sampling_params(self) -> Optional[SamplingParams]: | ||
| return self.get("sampling_params") | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Align example requirement with package version and add a safe upper bound.
The plugin's version module is 0.1.0, but the example depends on >=0.0.1. Consider aligning and capping to avoid future breaking changes.
Apply:
Verify the package/version exists on PyPI:
🏁 Script executed:
Length of output: 49
🏁 Script executed:
Length of output: 3
Correct or publish the referenced package before pinning versions.
The
livekit-plugins-respeecherpackage is not found on PyPI (HTTP 404); please confirm the correct package name or publish this plugin before updating the example’s requirements.🤖 Prompt for AI Agents