Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/tts_prefs #64

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions ovos_bus_client/session.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import enum
import time
from threading import Lock
from typing import Optional, List, Tuple, Union, Iterable
from typing import Optional, List, Tuple, Union, Iterable, Dict
from uuid import uuid4

from ovos_config.config import Configuration
Expand All @@ -17,7 +17,7 @@ class UtteranceState(str, enum.Enum):


class IntentContextManagerFrame:
def __init__(self, entities: List[dict] = None, metadata: dict = None):
def __init__(self, entities: List[dict] = None, metadata: Dict = None):
"""
Manages entities and context for a single frame of conversation.
Provides simple equality querying.
Expand All @@ -36,15 +36,15 @@ def serialize(self) -> dict:
"metadata": self.metadata}

@staticmethod
def deserialize(data: dict):
def deserialize(data: Dict):
"""
Build an IntentContextManagerFrame from serialized data
@param data: serialized (dict) frame data
@return: IntentContextManagerFrame for the specified data
"""
return IntentContextManagerFrame(**data)

def metadata_matches(self, query: dict = None) -> bool:
def metadata_matches(self, query: Dict = None) -> bool:
"""
Returns key matches to metadata
Asserts that the contents of query exist within (logical subset of)
Expand All @@ -65,7 +65,7 @@ def metadata_matches(self, query: dict = None) -> bool:

return result

def merge_context(self, tag: dict, metadata: dict):
def merge_context(self, tag: Dict, metadata: Dict):
"""
merge into contextManagerFrame new entity and metadata.
Appends tag as new entity and adds keys in metadata to keys in
Expand Down Expand Up @@ -119,7 +119,7 @@ def serialize(self) -> dict:
in self.frame_stack]}

@staticmethod
def deserialize(data: dict):
def deserialize(data: Dict):
"""
Build an IntentContextManager from serialized data
@param data: serialized (dict) data
Expand All @@ -130,7 +130,7 @@ def deserialize(data: dict):
for (f, t) in data.get("frame_stack", [])]
return IntentContextManager(timeout, framestack)

def update_context(self, entities: dict):
def update_context(self, entities: Dict):
"""
Updates context with keyword from the intent.

Expand Down Expand Up @@ -162,7 +162,7 @@ def remove_context(self, context_id: str):
self.frame_stack = [(f, t) for (f, t) in self.frame_stack
if context_id in f.entities[0].get('data', [])]

def inject_context(self, entity: dict, metadata: dict = None):
def inject_context(self, entity: Dict, metadata: Dict = None):
"""
Add context to the first frame in the stack. If no frame metadata
doesn't match the passed metadata then a new one is inserted.
Expand Down Expand Up @@ -263,10 +263,12 @@ def get_context(self, max_frames: int = None,
class Session:
def __init__(self, session_id: str = None, expiration_seconds: int = None,
active_skills: List[List[Union[str, float]]] = None,
utterance_states: dict = None, lang: str = None,
utterance_states: Dict = None, lang: str = None,
context: IntentContextManager = None,
site_id: str = "unknown",
pipeline: List[str] = None):
pipeline: List[str] = None,
stt_prefs: Dict = None,
tts_prefs: Dict = None):
"""
Construct a session identifier
@param session_id: string UUID for the session
Expand All @@ -277,7 +279,9 @@ def __init__(self, session_id: str = None, expiration_seconds: int = None,
@param context: IntentContextManager for this Session
"""
self.session_id = session_id or str(uuid4())

self.lang = lang or get_default_lang()

self.site_id = site_id or "unknown" # indoors placement info

self.active_skills = active_skills or [] # [skill_id , timestamp]# (Message , timestamp)
Expand All @@ -299,6 +303,20 @@ def __init__(self, session_id: str = None, expiration_seconds: int = None,
]
self.context = context or IntentContextManager()

if not stt_prefs:
stt = Configuration().get("stt", {})
sttm = stt.get("module", "ovos-stt-plugin-server")
stt_prefs = {"plugin_id": sttm,
"config": stt.get(sttm) or {}}
self.stt_preferences = stt_prefs

if not tts_prefs:
tts = Configuration().get("tts", {})
ttsm = tts.get("module", "ovos-tts-plugin-server")
tts_prefs = {"plugin_id": ttsm,
"config": tts.get(ttsm) or {}}
self.tts_preferences = tts_prefs
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved

@property
def active(self) -> bool:
"""
Expand Down Expand Up @@ -392,7 +410,9 @@ def serialize(self) -> dict:
"lang": self.lang,
"context": self.context.serialize(),
"site_id": self.site_id,
"pipeline": self.pipeline
"pipeline": self.pipeline,
"stt": self.stt_preferences,
"tts": self.tts_preferences
}

def update_history(self, message: Message = None):
Expand All @@ -404,7 +424,7 @@ def update_history(self, message: Message = None):
"session no longer has a message history")

@staticmethod
def deserialize(data: dict):
def deserialize(data: Dict):
"""
Build a Session object from dict data
@param data: dict serialized Session object
Expand All @@ -417,13 +437,17 @@ def deserialize(data: dict):
context = IntentContextManager.deserialize(data.get("context", {}))
site_id = data.get("site_id", "unknown")
pipeline = data.get("pipeline", [])
tts = data.get("tts_preferences", {})
stt = data.get("stt_preferences", {})
return Session(uid,
active_skills=active,
utterance_states=states,
lang=lang,
context=context,
pipeline=pipeline,
site_id=site_id)
site_id=site_id,
tts_prefs=tts,
stt_prefs=stt)

@staticmethod
def from_message(message: Message = None):
Expand Down
Loading