forked from pipecat-ai/pipecat
-
Notifications
You must be signed in to change notification settings - Fork 0
Add Respeecher TTS #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
Kharacternyk
wants to merge
25
commits into
main
Choose a base branch
from
respeecher
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
25 commits
Select commit
Hold shift + click to select a range
10db1bd
Add a dependency group for Respeecher
Kharacternyk 24565b2
Add Respeecher to env.example
Kharacternyk c488706
Spit the audio context functionality out
Kharacternyk 1417791
Fix some typos
Kharacternyk 051c5fc
Make the type checker happy
Kharacternyk ee2f11d
Rename a class
Kharacternyk eb467d4
Add a link to the future docs page
Kharacternyk c9a12b4
Add initial implementation
Kharacternyk 5efe01b
Fix some issues
Kharacternyk adadc6a
Refactor
Kharacternyk 554ff8e
Forbid overriding encoding
Kharacternyk d26e2fb
Use a TypedDict for convenience
Kharacternyk 44b3ed0
Add some more type checking
Kharacternyk 999d073
Add a foundational example
Kharacternyk f640eae
Fix an example
Kharacternyk 1e19dac
Move sampling params into settings
Kharacternyk d565fc0
Switch back to single context
Kharacternyk fa4624b
Refactor
Kharacternyk 79b9f28
Merge branch 'main' into respeecher
Kharacternyk 233fef4
Remove the watchdog
Kharacternyk b0e971b
Fix a docstring
Kharacternyk fbdb350
Adjust a dependency specifier
Kharacternyk 62b5427
Merge branch 'main' into respeecher
Kharacternyk e1a9c1b
Fix a type hint
Kharacternyk d6ee787
Merge branch 'main' into respeecher
Kharacternyk 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
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,126 @@ | ||
| # | ||
| # Copyright (c) 2024–2025, Daily | ||
| # | ||
| # SPDX-License-Identifier: BSD 2-Clause License | ||
| # | ||
|
|
||
| import os | ||
|
|
||
| from dotenv import load_dotenv | ||
| from loguru import logger | ||
|
|
||
| from pipecat.audio.vad.silero import SileroVADAnalyzer | ||
| from pipecat.pipeline.pipeline import Pipeline | ||
| from pipecat.pipeline.runner import PipelineRunner | ||
| from pipecat.pipeline.task import PipelineParams, PipelineTask | ||
| from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext | ||
| from pipecat.runner.types import RunnerArguments | ||
| from pipecat.runner.utils import create_transport | ||
| from pipecat.services.deepgram.stt import DeepgramSTTService | ||
| from pipecat.services.openai.llm import OpenAILLMService | ||
| from pipecat.services.respeecher.tts import RespeecherTTSService | ||
| from pipecat.transports.base_transport import BaseTransport, TransportParams | ||
| from pipecat.transports.network.fastapi_websocket import FastAPIWebsocketParams | ||
| from pipecat.transports.services.daily import DailyParams | ||
|
|
||
| load_dotenv(override=True) | ||
|
|
||
| # We store functions so objects (e.g. SileroVADAnalyzer) don't get | ||
| # instantiated. The function will be called when the desired transport gets | ||
| # selected. | ||
| transport_params = { | ||
| "daily": lambda: DailyParams( | ||
| audio_in_enabled=True, | ||
| audio_out_enabled=True, | ||
| vad_analyzer=SileroVADAnalyzer(), | ||
| ), | ||
| "twilio": lambda: FastAPIWebsocketParams( | ||
| audio_in_enabled=True, | ||
| audio_out_enabled=True, | ||
| vad_analyzer=SileroVADAnalyzer(), | ||
| ), | ||
| "webrtc": lambda: TransportParams( | ||
| audio_in_enabled=True, | ||
| audio_out_enabled=True, | ||
| vad_analyzer=SileroVADAnalyzer(), | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| async def run_bot(transport: BaseTransport, runner_args: RunnerArguments): | ||
| logger.info(f"Starting bot") | ||
|
|
||
| stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY")) | ||
|
|
||
| tts = RespeecherTTSService( | ||
| api_key=os.getenv("RESPEECHER_API_KEY"), | ||
| voice_id="samantha", | ||
| params=RespeecherTTSService.InputParams( | ||
| sampling_params={ | ||
| # Optional sampling params overrides | ||
| # See https://space.respeecher.com/docs/api/tts/sampling-params-guide | ||
| # "temperature": 0.5 | ||
| }, | ||
| ), | ||
| ) | ||
|
|
||
| llm = OpenAILLMService(api_key=os.getenv("OPENAI_API_KEY")) | ||
|
|
||
| messages = [ | ||
| { | ||
| "role": "system", | ||
| "content": "You are a helpful LLM in a WebRTC call. Your goal is to demonstrate your capabilities in a succinct way. Your output will be converted to audio so don't include special characters in your answers. Respond to what the user said in a creative and helpful way.", | ||
| }, | ||
| ] | ||
|
|
||
| context = OpenAILLMContext(messages) | ||
| context_aggregator = llm.create_context_aggregator(context) | ||
|
|
||
| pipeline = Pipeline( | ||
| [ | ||
| transport.input(), # Transport user input | ||
| stt, | ||
| context_aggregator.user(), # User responses | ||
| llm, # LLM | ||
| tts, # TTS | ||
| transport.output(), # Transport bot output | ||
| context_aggregator.assistant(), # Assistant spoken responses | ||
| ] | ||
| ) | ||
|
|
||
| task = PipelineTask( | ||
| pipeline, | ||
| params=PipelineParams( | ||
| enable_metrics=True, | ||
| enable_usage_metrics=True, | ||
| ), | ||
| idle_timeout_secs=runner_args.pipeline_idle_timeout_secs, | ||
| ) | ||
|
|
||
| @transport.event_handler("on_client_connected") | ||
| async def on_client_connected(transport, client): | ||
| logger.info(f"Client connected") | ||
| # Kick off the conversation. | ||
| messages.append({"role": "system", "content": "Please introduce yourself to the user."}) | ||
| await task.queue_frames([context_aggregator.user().get_context_frame()]) | ||
|
|
||
| @transport.event_handler("on_client_disconnected") | ||
| async def on_client_disconnected(transport, client): | ||
| logger.info(f"Client disconnected") | ||
| await task.cancel() | ||
|
|
||
| runner = PipelineRunner(handle_sigint=runner_args.handle_sigint) | ||
|
|
||
| await runner.run(task) | ||
|
|
||
|
|
||
| async def bot(runner_args: RunnerArguments): | ||
| """Main bot entry point compatible with Pipecat Cloud.""" | ||
| transport = await create_transport(runner_args, transport_params) | ||
| await run_bot(transport, runner_args) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| from pipecat.runner.run import main | ||
|
|
||
| main() | ||
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
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.
This comment is a little confusing because it looks like you do call
SileroVADAnalyzerThere 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.
It's called in a lambda on-demand, not at the top-level. This comment is the same across examples with different TTSes, our custom code is just lines 55-65