Update Lmnt TTS to support updating settings dynamically
This commit is contained in:
@@ -100,8 +100,8 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
await task.queue_frames([LLMRunFrame()])
|
await task.queue_frames([LLMRunFrame()])
|
||||||
|
|
||||||
await asyncio.sleep(10)
|
await asyncio.sleep(10)
|
||||||
logger.info('Updating LMNT TTS settings: voice="lily"')
|
logger.info('Updating LMNT TTS settings: voice="tyler"')
|
||||||
await task.queue_frame(TTSUpdateSettingsFrame(update=LmntTTSSettings(voice="lily")))
|
await task.queue_frame(TTSUpdateSettingsFrame(update=LmntTTSSettings(voice="tyler")))
|
||||||
|
|
||||||
@transport.event_handler("on_client_disconnected")
|
@transport.event_handler("on_client_disconnected")
|
||||||
async def on_client_disconnected(transport, client):
|
async def on_client_disconnected(transport, client):
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import AsyncGenerator, Optional
|
from typing import Any, AsyncGenerator, Optional
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
@@ -207,6 +207,23 @@ class LmntTTSService(InterruptibleTTSService):
|
|||||||
|
|
||||||
await self._disconnect_websocket()
|
await self._disconnect_websocket()
|
||||||
|
|
||||||
|
async def _update_settings(self, update: TTSSettings) -> dict[str, Any]:
|
||||||
|
"""Apply a settings update.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
update: A :class:`TTSSettings` (or ``LmntTTSSettings``) delta.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Dict mapping changed field names to their previous values.
|
||||||
|
"""
|
||||||
|
changed = await super()._update_settings(update)
|
||||||
|
|
||||||
|
if changed:
|
||||||
|
await self._disconnect()
|
||||||
|
await self._connect()
|
||||||
|
|
||||||
|
return changed
|
||||||
|
|
||||||
async def _connect_websocket(self):
|
async def _connect_websocket(self):
|
||||||
"""Connect to LMNT websocket."""
|
"""Connect to LMNT websocket."""
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user