tts: don't connect to websocket if already connected

This commit is contained in:
Aleix Conchillo Flaqué
2025-02-24 22:33:13 -08:00
parent 1ec68bd071
commit fb7fe540f5
6 changed files with 17 additions and 0 deletions

View File

@@ -194,6 +194,8 @@ class CartesiaTTSService(AudioContextWordTTSService):
async def _connect_websocket(self):
try:
if self._websocket:
return
logger.debug("Connecting to Cartesia")
self._websocket = await websockets.connect(
f"{self._url}?api_key={self._api_key}&cartesia_version={self._cartesia_version}"

View File

@@ -308,6 +308,9 @@ class ElevenLabsTTSService(InterruptibleWordTTSService):
async def _connect_websocket(self):
try:
if self._websocket:
return
logger.debug("Connecting to ElevenLabs")
voice_id = self._voice_id

View File

@@ -118,6 +118,9 @@ class FishAudioTTSService(InterruptibleTTSService):
async def _connect_websocket(self):
try:
if self._websocket:
return
logger.debug("Connecting to Fish Audio")
headers = {"Authorization": f"Bearer {self._api_key}"}
self._websocket = await websockets.connect(self._base_url, extra_headers=headers)

View File

@@ -124,6 +124,9 @@ class LmntTTSService(InterruptibleTTSService):
async def _connect_websocket(self):
"""Connect to LMNT websocket."""
try:
if self._websocket:
return
logger.debug("Connecting to LMNT")
# Build initial connection message

View File

@@ -171,6 +171,9 @@ class PlayHTTTSService(InterruptibleTTSService):
async def _connect_websocket(self):
try:
if self._websocket:
return
logger.debug("Connecting to PlayHT")
if not self._websocket_url:

View File

@@ -180,6 +180,9 @@ class RimeTTSService(AudioContextWordTTSService):
async def _connect_websocket(self):
"""Connect to Rime websocket API with configured settings."""
try:
if self._websocket:
return
params = "&".join(f"{k}={v}" for k, v in self._settings.items())
url = f"{self._url}?{params}"
headers = {"Authorization": f"Bearer {self._api_key}"}