clever-apartment-50437
09/16/2025, 2:12 PMtall-airline-16756
09/16/2025, 2:12 PMtall-airline-16756
09/16/2025, 2:13 PMpip install "livekit-agents[speechify]~=1.2"
2. Next, create a .env file in your project root and add your Speechify API key:
SPEECHIFY_API_KEY=your_api_key_here
3. Then, use the following Python code for the integration:
import asyncio
import logging
from dotenv import load_dotenv
from livekit import rtc
from livekit.agents import AutoSubscribe, JobContext, WorkerOptions, cli
from livekit.agents.tts import TTSCapabilities
from livekit.plugins import speechify
load_dotenv()
logger = logging.getLogger("speechify-tts-demo")
logger.setLevel(<http://logging.INFO|logging.INFO>)
async def entrypoint(ctx: JobContext):
try:
await ctx.connect(auto_subscribe=AutoSubscribe.SUBSCRIBE_NONE)
participant = await ctx.wait_for_participant()
<http://logger.info|logger.info>("Connected to LiveKit room and participant joined")
tts = speechify.TTS(voice_id="jack", model="simba-english", language="en", encoding="mp3_24000", loudness_normalization=True, text_normalization=True)
assert isinstance(tts.capabilities, TTSCapabilities)
<http://logger.info|logger.info>(f"TTS initialized with sample rate: {tts.sample_rate}")
source = rtc.AudioSource(tts.sample_rate, tts.num_channels)
track = rtc.LocalAudioTrack.create_audio_track("tts-audio", source)
options = rtc.TrackPublishOptions()
options.source = rtc.TrackSource.SOURCE_MICROPHONE
publication = await ctx.room.local_participant.publish_track(track, options)
await publication.wait_for_subscription()
<http://logger.info|logger.info>("Audio track published successfully")
text = "Hello! I'm using Speechify TTS with LiveKit Agents to convert this text into natural-sounding speech in real time."
async for output in tts.synthesize(text):
await source.capture_frame(output.frame)
<http://logger.info|logger.info>("TTS synthesis completed successfully")
except Exception as e:
logger.error("An error occurred in the TTS agent: %s", str(e), exc_info=True)
raise
finally:
if 'tts' in locals():
await tts.aclose()
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
If you'd like, you can also explore listing available voices programmatically or using SSML for more advanced speech control. Please feel free to reach out if you have any questions or need a hand with anything else—I’m here to help!
Sources: Speechify TTS integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-speechify/pyproject.tomlclever-apartment-50437
09/16/2025, 2:15 PMtall-airline-16756
09/16/2025, 2:15 PMssml_text = ''
async for output in tts.synthesize(ssml_text):
await source.capture_frame(output.frame)
Just swap out the ssml_text content with your own SSML markup. If you have any questions or want me to walk you through it, I’m here to help!clever-apartment-50437
09/16/2025, 2:19 PMtall-airline-16756
09/16/2025, 2:19 PM<https://api.sws.speechify.com/v1/audio/stream>
Here’s how you can structure your request:
• HTTP Method: POST
• Headers:
◦ Authorization: Bearer <your_api_key>
◦ Accept: audio/<format> (for example, audio/ogg if you’re using ogg_24000)
◦ x-caller: livekit
• Request Body (JSON):
{
"input": "text to synthesize",
"voice_id": "specified_voice_id",
"language": "language_code_if_provided",
"model": "simba-english",
"audio_format": "ogg",
"options": {
"loudness_normalization": true_or_false_if_set,
"text_normalization": true_or_false_if_set
}
}
Just be sure to swap out <your_api_key> with your actual Speechify API key, and feel free to tweak the body parameters to fit your needs. If you have any questions or want me to walk you through any part of this, I’m here to help!
Sources: examples/other/text-to-speech/rime_tts.py | Speechify TTS integration guide | LiveKit Docs