Skip to content
Snippets Groups Projects
Commit f83e15c1 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Merge branch 'armar6-dev' into 'master'

Armar6 dev

See merge request !34
parents 5288dee7 e417dabe
No related branches found
No related tags found
1 merge request!34Armar6 dev
Pipeline #9532 failed
from typing import Dict, List, Optional
from armarx_memory.core import MemoryID
from armarx_memory.client import MemoryNameSystem, Commit, Reader, Writer
class TextToSpeech:
def __init__(
self,
text: str,
):
self.text = text
def to_aron(self) -> "armarx.aron.data.dto.GenericData":
from armarx_memory.aron.conversion import to_aron
dto = to_aron(
{
"text": self.text,
}
)
return dto
@classmethod
def from_aron(cls, dto: "armarx.aron.data.dto.GenericData"):
from armarx_memory.aron.conversion import from_aron
d = from_aron(dto)
return cls(**d)
def __repr__(self):
return "<{c} text='{t}'>".format(c=self.__class__.__name__, t=self.text)
class TextToSpeechClientBase:
core_segment_id = MemoryID("Speech", "TextToSpeech")
def __init__(self):
pass
def make_entity_name(self, provider_name: str, entity_name: str = "text"):
return self.core_segment_id.with_provider_segment_name(
provider_name
).with_entity_name(entity_name)
class TextToSpeechWriter(TextToSpeechClientBase):
def __init__(self, writer: Writer):
super().__init__()
self.writer = writer
@classmethod
def from_mns(cls, mns: MemoryNameSystem, wait=True) -> "TextToSpeechWriter":
return cls(
mns.wait_for_writer(cls.core_segment_id)
if wait
else mns.get_writer(cls.core_segment_id)
)
def commit(
self,
entity_id: MemoryID,
text: str,
time_created_usec=None,
**kwargs,
):
commit = Commit()
commit.add(
entity_id=entity_id,
time_created_usec=time_created_usec,
instances_data=[TextToSpeech(text=text).to_aron()],
**kwargs,
)
return self.writer.commit(commit)
class TextToSpeechReader(TextToSpeechClientBase):
def __init__(self, reader: Reader):
super().__init__()
self.reader = reader
def fetch_latest_instance(self, updated_ids: Optional[List[MemoryID]] = None):
"""
Query the latest snapshot of the given updated IDs and
return its first instance.
"""
if updated_ids is None:
memory = self.reader.query_latest(self.core_segment_id)
latest_snapshot = None
core_seg = memory.coreSegments[self.core_segment_id.core_segment_name]
for prov_seg in core_seg.providerSegments.values():
for entity in prov_seg.entities.values():
for snapshot in entity.history.values():
if latest_snapshot is None:
latest_snapshot = snapshot
elif (
latest_snapshot.id.timestamp.timeSinceEpoch.microSeconds
< snapshot.id.timestamp.timeSinceEpoch.microSeconds
):
latest_snapshot = snapshot
else:
for up_id in updated_ids:
assert self.core_segment_id.contains(up_id)
latest_snapshot_id = max(updated_ids, key=lambda i: i.timestamp_usec)
latest_snapshot = self.reader.query_snapshot(latest_snapshot_id)
latest_instance = latest_snapshot.instances[0]
return latest_instance
@classmethod
def from_mns(cls, mns: MemoryNameSystem, wait=True) -> "TextToSpeechReader":
return cls(
mns.wait_for_reader(cls.core_segment_id)
if wait
else mns.get_reader(cls.core_segment_id)
)
from armarx_memory.segments.speech.text_to_speech import *
import enum
from armarx_memory.core import MemoryID
from armarx_memory.client.detail import SpecialClientBase as scb
class TextToSpeechStateWriter(scb.SpecialWriterBase):
@classmethod
def _get_aron_class(cls):
return TextToSpeechState
@classmethod
def _get_default_core_segment_id(cls):
return TextToSpeechState.core_segment_id
class TextToSpeechStateReader(scb.SpecialReaderBase):
@classmethod
def _get_aron_class(cls):
return TextToSpeechState
@classmethod
def _get_default_core_segment_id(cls):
return TextToSpeechState.core_segment_id
class TextToSpeechState:
class Event(enum.IntEnum):
STARTED = 0
FINISHED = 1
core_segment_id = MemoryID("Speech", "TextToSpeechState")
Reader = TextToSpeechStateReader
Writer = TextToSpeechStateWriter
def __init__(
self,
event: Event,
text: str,
tts_snapshot_id: MemoryID,
):
self.event = event
self.text = text
self.tts_snapshot_id = tts_snapshot_id
def to_aron(self) -> "armarx.aron.data.dto.GenericData":
from armarx_memory.aron.conversion import to_aron
dto = to_aron(
{
"event": self.event,
"text": self.text,
"ttsSnapshotID": self.tts_snapshot_id,
}
)
return dto
@classmethod
def from_aron(cls, dto: "armarx.aron.data.dto.GenericData"):
from armarx_memory.aron.conversion import from_aron
d = from_aron(dto)
d["tts_snapshot_id"] = d.pop("ttsSnapshotID")
return cls(**d)
def __repr__(self):
return "<{c} event='{e}' tts ID={tts} text={text}>".format(
c=self.__class__.__name__,
e=self.event,
tts=self.tts_snapshot_id,
text=self.text,
)
from armarx_memory.segments.speech.text_to_speech_state import *
import dataclasses as dc
import typing as ty
from armarx_memory.aron.aron_dataclass import AronDataclass
from armarx_memory.core import MemoryID
from armarx_memory.client import MemoryNameSystem, Commit, Reader, Writer
@dc.dataclass
class TextToSpeech(AronDataclass):
text: str
class TextToSpeechClientBase:
core_segment_id = MemoryID("Speech", "TextToSpeech")
def __init__(self):
pass
def make_entity_name(self, provider_name: str, entity_name: str = "text"):
return self.core_segment_id.with_provider_segment_name(
provider_name
).with_entity_name(entity_name)
class TextToSpeechWriter(TextToSpeechClientBase):
def __init__(self, writer: Writer):
super().__init__()
self.writer = writer
@classmethod
def from_mns(cls, mns: MemoryNameSystem, wait=True) -> "TextToSpeechWriter":
return cls(
mns.wait_for_writer(cls.core_segment_id)
if wait
else mns.get_writer(cls.core_segment_id)
)
def commit(
self,
entity_id: MemoryID,
text: str,
time_created_usec=None,
**kwargs,
):
commit = Commit()
commit.add(
entity_id=entity_id,
time_created_usec=time_created_usec,
instances_data=[TextToSpeech(text=text).to_aron_ice()],
**kwargs,
)
return self.writer.commit(commit)
class TextToSpeechReader(TextToSpeechClientBase):
def __init__(self, reader: Reader):
super().__init__()
self.reader = reader
def fetch_latest_instance(self, updated_ids: ty.Optional[ty.List[MemoryID]] = None):
"""
Query the latest snapshot of the given updated IDs and
return its first instance.
"""
if updated_ids is None:
memory = self.reader.query_latest(self.core_segment_id)
latest_snapshot = None
core_seg = memory.coreSegments[self.core_segment_id.core_segment_name]
for prov_seg in core_seg.providerSegments.values():
for entity in prov_seg.entities.values():
for snapshot in entity.history.values():
if latest_snapshot is None:
latest_snapshot = snapshot
elif (
latest_snapshot.id.timestamp.timeSinceEpoch.microSeconds
< snapshot.id.timestamp.timeSinceEpoch.microSeconds
):
latest_snapshot = snapshot
else:
for up_id in updated_ids:
assert self.core_segment_id.contains(up_id)
latest_snapshot_id = max(updated_ids, key=lambda i: i.timestamp_usec)
latest_snapshot = self.reader.query_snapshot(latest_snapshot_id)
latest_instance = latest_snapshot.instances[0]
return latest_instance
@classmethod
def from_mns(cls, mns: MemoryNameSystem, wait=True) -> "TextToSpeechReader":
return cls(
mns.wait_for_reader(cls.core_segment_id)
if wait
else mns.get_reader(cls.core_segment_id)
)
import enum
import dataclasses as dc
import typing as ty
from armarx_memory.aron.aron_dataclass import AronDataclass
from armarx_memory.core import MemoryID
from armarx_memory.client.detail import SpecialClientBase as scb
CORE_SEGMENT_ID = MemoryID("Speech", "TextToSpeechState")
@dc.dataclass
class TextToSpeechState(AronDataclass):
class Event(enum.IntEnum):
STARTED = 0
FINISHED = 1
event: Event
text: str
tts_snapshot_id: MemoryID
core_segment_id: ty.ClassVar[MemoryID] = CORE_SEGMENT_ID
@classmethod
def _get_conversion_options(cls) -> ty.Optional["ConversionOptions"]:
from armarx_memory.aron.conversion.options import ConversionOptions
return ConversionOptions(
names_python_to_aron_dict={
"tts_snapshot_id": "ttsSnapshotID",
},
)
class TextToSpeechStateWriter(scb.SpecialWriterBase):
core_segment_id = CORE_SEGMENT_ID
@classmethod
def _get_aron_class(cls):
return TextToSpeechState
@classmethod
def _get_default_core_segment_id(cls):
return TextToSpeechState.core_segment_id
class TextToSpeechStateReader(scb.SpecialReaderBase):
core_segment_id = CORE_SEGMENT_ID
@classmethod
def _get_aron_class(cls):
return TextToSpeechState
@classmethod
def _get_default_core_segment_id(cls):
return TextToSpeechState.core_segment_id
......@@ -7,6 +7,7 @@ from armarx_skills.manager import skill_execution_request
from armarx_skills.provider import dto as provider_dto
from armarx_skills.provider import skill_status_update
from armarx_skills.provider.skill_id import SkillID
......@@ -47,10 +48,43 @@ class SkillManager:
update: provider_dto.SkillStatusUpdate = self.proxy.executeSkill(skillExecutionInfo=request)
return self.skill_status_update_conv.from_ice(update)
def execute_skill_with_default_params(
self,
executor_name: str,
skill_id: SkillID,
):
descriptions_ice = self.get_skill_descriptions()
description_ice = descriptions_ice[skill_id.provider_name][skill_id.skill_name]
default_params = description_ice.defaultParams
self.execute_skill(skill_execution_request.SkillExecutionRequest(
executor_name=executor_name,
skill_id=skill_id,
params=default_params,
))
def abort_skill(self, provider_name: str, skill_name: str) -> None:
return self.proxy.abortSkill(providerName=provider_name, skillName=skill_name)
class ReconnectingSkillManager:
def __init__(self):
self._skill_manager: ty.Optional[SkillManager] = None
def get(self, logger=None) -> SkillManager:
self.connect(logger=logger)
return self._skill_manager
def connect(self, logger=None):
if self._skill_manager is None:
name = SkillManager.DEFAULT_ICE_OBJECT_NAME
if logger is not None:
logger.info(f"Waiting for skill manager '{name}' ...")
self._skill_manager = SkillManager.wait_for_manager(name=name)
if __name__ == '__main__':
def test_main():
manager = SkillManager.wait_for_manager()
......
......@@ -9,6 +9,12 @@ from armarx.skills.provider.dto import \
SkillID, SkillDescription, SkillExecutionRequest, SkillStatusUpdateHeader, SkillStatusUpdate
from armarx.skills.provider.dto.Execution import Status
Status.Idle
Status.Scheduled
Status.Running
Status.Failed
Status.Succeeded
Status.Aborted
SkillDescriptionMap = ty.Dict[str, SkillDescription]
SkillStatusUpdateMap = ty.Dict[str, SkillStatusUpdate]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment