Merge pull request #2296 from pipecat-ai/mb/switch-rime-voices

Added the ability to switch voices to RimeTTSService
This commit is contained in:
Mark Backman
2025-07-30 07:55:52 -07:00
committed by GitHub
2 changed files with 14 additions and 1 deletions

View File

@@ -13,7 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
A video service that handles audio streaming and requests HeyGen to generate A video service that handles audio streaming and requests HeyGen to generate
avatar video responses. (see https://www.heygen.com/) avatar video responses. (see https://www.heygen.com/)
- Added the ability to switch voices to `RimeTTSService`.
- Added Async.ai TTS integration (https://async.ai/) - Added Async.ai TTS integration (https://async.ai/)
- `AsyncAITTSService` WebSocket-based streaming TTS with interruption support - `AsyncAITTSService` WebSocket-based streaming TTS with interruption support
- `AsyncAIHttpTTSService` HTTP-based streaming TTS service - `AsyncAIHttpTTSService` HTTP-based streaming TTS service
- Example scripts: - Example scripts:

View File

@@ -13,7 +13,7 @@ using Rime's API for streaming and batch audio synthesis.
import base64 import base64
import json import json
import uuid import uuid
from typing import AsyncGenerator, Optional from typing import Any, AsyncGenerator, Mapping, Optional
import aiohttp import aiohttp
from loguru import logger from loguru import logger
@@ -181,6 +181,16 @@ class RimeTTSService(AudioContextWordTTSService):
self._model = model self._model = model
await super().set_model(model) await super().set_model(model)
async def _update_settings(self, settings: Mapping[str, Any]):
"""Update service settings and reconnect if voice changed."""
prev_voice = self._voice_id
await super()._update_settings(settings)
if not prev_voice == self._voice_id:
self._settings["speaker"] = self._voice_id
logger.info(f"Switching TTS voice to: [{self._voice_id}]")
await self._disconnect()
await self._connect()
def _build_msg(self, text: str = "") -> dict: def _build_msg(self, text: str = "") -> dict:
"""Build JSON message for Rime API.""" """Build JSON message for Rime API."""
return {"text": text, "contextId": self._context_id} return {"text": text, "contextId": self._context_id}