FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add playStream in g1 audio client by animaRoboticsTeam · Pull Request #70 · unitreerobotics/unitree_sdk2_python · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 8 additions & 0 deletions unitree_sdk2py/g1/audio/g1_audio_client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def TtsMaker(self, text: str, speaker_id: int):
code, data = self._Call(ROBOT_API_ID_AUDIO_TTS, parameter)
return code

def PlayStream(self, app_name: str, stream_id: str, pcm_data: list):
p = {}
p["app_name"] = app_name
p["stream_id"] = stream_id
parameter = json.dumps(p)
code, data = self._CallParamBinary(ROBOT_API_ID_AUDIO_START_PLAY, parameter, pcm_data)
return code

def GetVolume(self):
p = {}
parameter = json.dumps(p)
Expand Down
7 changes: 7 additions & 0 deletions unitree_sdk2py/rpc/client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ def _CallBinaryNoReply(self, apiId: int, parameter: list):
else:
return RPC_ERR_CLIENT_API_NOT_REG

def _CallParamBinary(self, apiId: int, parameter: str, binary: list):
ret, proirity, leaseId = self.__CheckApi(apiId)
if ret == 0:
return self._CallParamBinaryBase(apiId, parameter, binary, proirity, leaseId)
else:
return RPC_ERR_CLIENT_API_NOT_REG, None

def _RegistApi(self, apiId: int, proirity: int):
self.__apiMapping[apiId] = proirity

Expand Down
22 changes: 22 additions & 0 deletions unitree_sdk2py/rpc/client_base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,28 @@ def _CallBinaryNoReplyBase(self, apiId: int, parameter: list, proirity: int, lea
else:
return RPC_ERR_CLIENT_SEND

def _CallParamBinaryBase(self, apiId: int, parameter: str, binary: list, proirity: int = 0, leaseId: int = 0):
header = self.__SetHeader(apiId, leaseId, proirity, False)
request = Request(header, parameter, binary)

future = self.__stub.SendRequest(request, self.__timeout)
if future is None:
return RPC_ERR_CLIENT_SEND, None

result = future.GetResult(self.__timeout)

if result.code != FutureResult.FUTURE_SUCC:
self.__stub.RemoveFuture(request.header.identity.id)
code = RPC_ERR_CLIENT_API_TIMEOUT if result.code == FutureResult.FUTUTE_ERR_TIMEOUT else RPC_ERR_UNKNOWN
return code, None

response = result.value

if response.header.identity.api_id != apiId:
return RPC_ERR_CLIENT_API_NOT_MATCH, None
else:
return response.header.status.code, response.data

def __SetHeader(self, apiId: int, leaseId: int, priority: int, noReply: bool):
identity = RequestIdentity(time.monotonic_ns(), apiId)
lease = RequestLease(leaseId)
Expand Down

Back | FazBrowse Home | New Git URL