Fixing RimeTTSService to reuse the same context when needed.
This commit is contained in:
@@ -12,6 +12,7 @@ using Rime's API for streaming and batch audio synthesis.
|
|||||||
|
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
|
import uuid
|
||||||
from typing import Any, AsyncGenerator, Mapping, Optional
|
from typing import Any, AsyncGenerator, Mapping, Optional
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
@@ -369,6 +370,20 @@ class RimeTTSService(AudioContextWordTTSService):
|
|||||||
|
|
||||||
return word_pairs
|
return word_pairs
|
||||||
|
|
||||||
|
def create_context_id(self) -> str:
|
||||||
|
"""Generate a unique context ID for a TTS request in case we don't have one already in progress.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A unique string identifier for the TTS context.
|
||||||
|
"""
|
||||||
|
# If a context ID does not exist, create a new one.
|
||||||
|
# If an ID exists, continue using the current ID.
|
||||||
|
# When interruptions happen, user speech results in
|
||||||
|
# an interruption, which resets the context ID.
|
||||||
|
if not self._context_id:
|
||||||
|
return str(uuid.uuid4())
|
||||||
|
return self._context_id
|
||||||
|
|
||||||
async def flush_audio(self):
|
async def flush_audio(self):
|
||||||
"""Flush any pending audio synthesis."""
|
"""Flush any pending audio synthesis."""
|
||||||
if not self._context_id or not self._websocket:
|
if not self._context_id or not self._websocket:
|
||||||
|
|||||||
Reference in New Issue
Block a user