init
This commit is contained in:
94
unitree_SDK/include/unitree/robot/g1/audio/g1_audio_api.hpp
Normal file
94
unitree_SDK/include/unitree/robot/g1/audio/g1_audio_api.hpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#ifndef __UT_ROBOT_G1_AUDIO_API_HPP__
|
||||
#define __UT_ROBOT_G1_AUDIO_API_HPP__
|
||||
|
||||
#include <unitree/common/json/jsonize.hpp>
|
||||
// #include <variant>
|
||||
|
||||
namespace unitree {
|
||||
namespace robot {
|
||||
namespace g1 {
|
||||
/*service name*/
|
||||
const std::string AUDIO_SERVICE_NAME = "voice";
|
||||
|
||||
/*api version*/
|
||||
const std::string AUDIO_API_VERSION = "1.0.0.0";
|
||||
|
||||
/*api id*/
|
||||
const int32_t ROBOT_API_ID_AUDIO_TTS = 1001;
|
||||
const int32_t ROBOT_API_ID_AUDIO_ASR = 1002;
|
||||
const int32_t ROBOT_API_ID_AUDIO_START_PLAY = 1003;
|
||||
const int32_t ROBOT_API_ID_AUDIO_STOP_PLAY = 1004;
|
||||
const int32_t ROBOT_API_ID_AUDIO_GET_VOLUME = 1005;
|
||||
const int32_t ROBOT_API_ID_AUDIO_SET_VOLUME = 1006;
|
||||
const int32_t ROBOT_API_ID_AUDIO_SET_RGB_LED = 1010;
|
||||
|
||||
class TtsMakerParameter : public common::Jsonize {
|
||||
public:
|
||||
TtsMakerParameter() {}
|
||||
~TtsMakerParameter() {}
|
||||
|
||||
void fromJson(common::JsonMap &json) {}
|
||||
|
||||
void toJson(common::JsonMap &json) const {
|
||||
common::ToJson(index, json["index"]);
|
||||
common::ToJson(speaker_id, json["speaker_id"]);
|
||||
common::ToJson(text, json["text"]);
|
||||
}
|
||||
|
||||
int32_t index = 0;
|
||||
uint16_t speaker_id = 0;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
class PlayStreamParameter : public common::Jsonize {
|
||||
public:
|
||||
PlayStreamParameter() {}
|
||||
~PlayStreamParameter() {}
|
||||
|
||||
void fromJson(common::JsonMap &json) {}
|
||||
|
||||
void toJson(common::JsonMap &json) const {
|
||||
common::ToJson(app_name, json["app_name"]);
|
||||
common::ToJson(stream_id, json["stream_id"]);
|
||||
}
|
||||
|
||||
std::string app_name;
|
||||
std::string stream_id;
|
||||
};
|
||||
|
||||
class PlayStopParameter : public common::Jsonize {
|
||||
public:
|
||||
PlayStopParameter() {}
|
||||
~PlayStopParameter() {}
|
||||
|
||||
void fromJson(common::JsonMap &json) {}
|
||||
|
||||
void toJson(common::JsonMap &json) const {
|
||||
common::ToJson(app_name, json["app_name"]);
|
||||
}
|
||||
|
||||
std::string app_name;
|
||||
};
|
||||
|
||||
class LedControlParameter : public common::Jsonize {
|
||||
public:
|
||||
LedControlParameter() {}
|
||||
~LedControlParameter() {}
|
||||
|
||||
void fromJson(common::JsonMap &json) {}
|
||||
|
||||
void toJson(common::JsonMap &json) const {
|
||||
common::ToJson(R, json["R"]);
|
||||
common::ToJson(G, json["G"]);
|
||||
common::ToJson(B, json["B"]);
|
||||
}
|
||||
|
||||
uint8_t R;
|
||||
uint8_t G;
|
||||
uint8_t B;
|
||||
};
|
||||
} // namespace g1
|
||||
} // namespace robot
|
||||
} // namespace unitree
|
||||
|
||||
#endif // __UT_ROBOT_G1_AUDIO_API_HPP__
|
110
unitree_SDK/include/unitree/robot/g1/audio/g1_audio_client.hpp
Normal file
110
unitree_SDK/include/unitree/robot/g1/audio/g1_audio_client.hpp
Normal file
@@ -0,0 +1,110 @@
|
||||
#ifndef __UT_ROBOT_G1_AUDIO_CLIENT_HPP__
|
||||
#define __UT_ROBOT_G1_AUDIO_CLIENT_HPP__
|
||||
|
||||
#include <limits>
|
||||
#include <unitree/robot/client/client.hpp>
|
||||
#include <unitree/robot/go2/public/jsonize_type.hpp>
|
||||
|
||||
#include "g1_audio_api.hpp"
|
||||
|
||||
namespace unitree {
|
||||
namespace robot {
|
||||
namespace g1 {
|
||||
class AudioClient : public Client {
|
||||
public:
|
||||
AudioClient() : Client(AUDIO_SERVICE_NAME, false) {}
|
||||
~AudioClient() {}
|
||||
|
||||
/*Init*/
|
||||
void Init() {
|
||||
SetApiVersion(AUDIO_API_VERSION);
|
||||
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_AUDIO_TTS);
|
||||
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_AUDIO_ASR);
|
||||
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_AUDIO_START_PLAY);
|
||||
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_AUDIO_STOP_PLAY);
|
||||
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_AUDIO_GET_VOLUME);
|
||||
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_AUDIO_SET_VOLUME);
|
||||
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_AUDIO_SET_RGB_LED);
|
||||
};
|
||||
|
||||
/*API Call*/
|
||||
int32_t TtsMaker(const std::string& text, int32_t speaker_id) {
|
||||
std::string parameter, data;
|
||||
TtsMakerParameter json;
|
||||
|
||||
json.index = tts_index++;
|
||||
json.text = text;
|
||||
json.speaker_id = speaker_id;
|
||||
parameter = common::ToJsonString(json);
|
||||
|
||||
return Call(ROBOT_API_ID_AUDIO_TTS, parameter, data);
|
||||
}
|
||||
|
||||
int32_t GetVolume(uint8_t& volume) {
|
||||
std::string parameter, data;
|
||||
|
||||
int32_t ret = Call(ROBOT_API_ID_AUDIO_GET_VOLUME, parameter, data);
|
||||
if (ret == 0) {
|
||||
unitree::robot::go2::JsonizeCommObjInt json;
|
||||
json.name = "volume";
|
||||
common::FromJsonString(data, json);
|
||||
volume = json.value;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t SetVolume(uint8_t volume) {
|
||||
std::string parameter, data;
|
||||
unitree::robot::go2::JsonizeCommObjInt json;
|
||||
|
||||
json.value = volume;
|
||||
json.name = "volume";
|
||||
parameter = common::ToJsonString(json);
|
||||
|
||||
return Call(ROBOT_API_ID_AUDIO_SET_VOLUME, parameter, data);
|
||||
}
|
||||
|
||||
int32_t PlayStream(std::string app_name, std::string stream_id,
|
||||
std::vector<uint8_t> pcm_data) {
|
||||
std::string parameter;
|
||||
PlayStreamParameter json;
|
||||
|
||||
json.app_name = app_name;
|
||||
json.stream_id = stream_id;
|
||||
parameter = common::ToJsonString(json);
|
||||
|
||||
return Call(ROBOT_API_ID_AUDIO_START_PLAY, parameter, pcm_data);
|
||||
}
|
||||
|
||||
int32_t PlayStop(std::string app_name) {
|
||||
std::string parameter, data;
|
||||
PlayStopParameter json;
|
||||
|
||||
json.app_name = app_name;
|
||||
parameter = common::ToJsonString(json);
|
||||
|
||||
Call(ROBOT_API_ID_AUDIO_STOP_PLAY, parameter, data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t LedControl(uint8_t R, uint8_t G, uint8_t B) {
|
||||
std::string parameter, data;
|
||||
LedControlParameter json;
|
||||
|
||||
json.R = R;
|
||||
json.G = G;
|
||||
json.B = B;
|
||||
parameter = common::ToJsonString(json);
|
||||
|
||||
return Call(ROBOT_API_ID_AUDIO_SET_RGB_LED, parameter, data);
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t tts_index = 0;
|
||||
};
|
||||
} // namespace g1
|
||||
|
||||
} // namespace robot
|
||||
} // namespace unitree
|
||||
#endif // __UT_ROBOT_G1_AUDIO_CLIENT_HPP__
|
@@ -0,0 +1,14 @@
|
||||
#ifndef __UT_ROBOT_G1_AUDIO_ERROR_HPP__
|
||||
#define __UT_ROBOT_G1_AUDIO_ERROR_HPP__
|
||||
|
||||
#include <unitree/common/decl.hpp>
|
||||
|
||||
namespace unitree {
|
||||
namespace robot {
|
||||
namespace g1 {
|
||||
UT_DECL_ERR(UT_ROBOT_AUDIO_ERR_COMM, 100, "Invalid parameter ")
|
||||
} // namespace g1
|
||||
} // namespace robot
|
||||
} // namespace unitree
|
||||
|
||||
#endif // __UT_ROBOT_G1_AUDIO_ERROR_HPP__
|
Reference in New Issue
Block a user