19#include <boost/filesystem.hpp>
20#include <boost/range/iterator_range.hpp>
27#include "modules/audio/proto/audio_conf.pb.h"
28#include "modules/common_msgs/audio_msgs/audio_event.pb.h"
29#include "modules/common_msgs/localization_msgs/localization.pb.h"
30#include "modules/common_msgs/perception_msgs/perception_obstacle.pb.h"
43 std::vector<std::string>* record_files) {
44 if (!boost::filesystem::exists(p)) {
47 if (boost::filesystem::is_regular_file(p)) {
48 AINFO <<
"Found record file: " << p.c_str();
49 record_files->push_back(p.c_str());
52 if (boost::filesystem::is_directory(p)) {
53 for (
auto& entry : boost::make_iterator_range(
54 boost::filesystem::directory_iterator(p), {})) {
61 const std::string& input_record_filepath,
62 const std::string& output_record_filepath,
70 writer.
Open(output_record_filepath);
75 if (audio_data.ParseFromString(message.
content)) {
77 std::string respeaker_extrinsics_file =
80 audio_info, direction_detection, moving_detection, siren_detection,
84 audio_detection, message.
time);
85 AINFO <<
"Generate a new audio detection message.";
90 if (audio_event.ParseFromString(message.
content)) {
93 AINFO <<
"Save an audio even message.";
98 if (localization.ParseFromString(message.
content)) {
101 AINFO <<
"Save a localization message.";
106 if (perception_obstacles.ParseFromString(message.
content)) {
109 AINFO <<
"Save a perception message.";
117 if (FLAGS_audio_records_dir.empty()) {
118 AERROR <<
"The input folder is empty";
130 std::vector<std::string> offline_bags;
133 std::sort(offline_bags.begin(), offline_bags.end());
134 for (std::size_t i = 0; i < offline_bags.size(); ++i) {
135 const std::string& input_record_filepath = offline_bags[i];
136 std::string output_record_filepath =
137 input_record_filepath +
".new_audio_detection";
139 output_record_filepath, &audio_info, &direction_detection,
140 &moving_detection, &siren_detection);
147int main(
int argc,
char* argv[]) {
148 google::ParseCommandLineFlags(&argc, &argv,
true);
int main(int argc, char *argv[])
static void OnMicrophone(const apollo::drivers::microphone::config::AudioData &audio_data, const std::string &respeaker_extrinsics_file, AudioInfo *audio_info, DirectionDetection *direction_detection, MovingDetection *moving_detection, SirenDetection *siren_detection, AudioDetection *audio_detection)
bool ReadMessage(RecordMessage *message, uint64_t begin_time=0, uint64_t end_time=std::numeric_limits< uint64_t >::max())
Read one message from reader.
bool Open(const std::string &file)
Open a record to write.
bool WriteMessage(const std::string &channel_name, const MessageT &message, const uint64_t time_nanosec, const std::string &proto_desc="")
Write a message to record.
void Close()
Clean the record.
void ProcessSingleRecordFile(const AudioConf &audio_conf, const std::string &input_record_filepath, const std::string &output_record_filepath, AudioInfo *audio_info, DirectionDetection *direction_detection, MovingDetection *moving_detection, SirenDetection *siren_detection)
void GetRecordFileNames(const boost::filesystem::path &p, std::vector< std::string > *record_files)
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
optional TopicConf topic_conf
optional string respeaker_extrinsics_path
optional string audio_data_topic_name
optional string audio_event_topic_name
optional string localization_topic_name
optional string perception_topic_name
optional string audio_detection_topic_name
Basic data struct of record message.
std::string content
The content of the message.
uint64_t time
The time (nanosecond) of the message.
std::string channel_name
The channel name of the message.