Skip to content

Add playStream in g1 audio client #70

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions unitree_sdk2py/g1/audio/g1_audio_client.py
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
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
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