2017-03-22 08:23:46 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/test/conversational_speech/timing.h"
|
2017-03-22 08:23:46 -07:00
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <iostream>
|
2022-08-16 14:44:38 +02:00
|
|
|
#include <string>
|
2017-03-22 08:23:46 -07:00
|
|
|
|
2022-08-16 14:44:38 +02:00
|
|
|
#include "absl/strings/string_view.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/string_encode.h"
|
2017-03-22 08:23:46 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
namespace conversational_speech {
|
|
|
|
|
|
|
|
|
|
bool Turn::operator==(const Turn& b) const {
|
|
|
|
|
return b.speaker_name == speaker_name &&
|
2018-01-22 14:18:28 +01:00
|
|
|
b.audiotrack_file_name == audiotrack_file_name && b.offset == offset &&
|
|
|
|
|
b.gain == gain;
|
2017-03-22 08:23:46 -07:00
|
|
|
}
|
|
|
|
|
|
2022-08-16 14:44:38 +02:00
|
|
|
std::vector<Turn> LoadTiming(absl::string_view timing_filepath) {
|
2017-03-22 08:23:46 -07:00
|
|
|
// Line parser.
|
2022-08-16 14:44:38 +02:00
|
|
|
auto parse_line = [](absl::string_view line) {
|
2022-06-07 13:58:27 +02:00
|
|
|
std::vector<absl::string_view> fields = rtc::split(line, ' ');
|
2018-01-22 14:18:28 +01:00
|
|
|
RTC_CHECK_GE(fields.size(), 3);
|
|
|
|
|
RTC_CHECK_LE(fields.size(), 4);
|
|
|
|
|
int gain = 0;
|
|
|
|
|
if (fields.size() == 4) {
|
2022-06-07 13:58:27 +02:00
|
|
|
gain = rtc::StringToNumber<int>(fields[3]).value_or(0);
|
2018-01-22 14:18:28 +01:00
|
|
|
}
|
2022-06-07 13:58:27 +02:00
|
|
|
return Turn(fields[0], fields[1],
|
|
|
|
|
rtc::StringToNumber<int>(fields[2]).value_or(0), gain);
|
2017-03-22 08:23:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Init.
|
|
|
|
|
std::vector<Turn> timing;
|
|
|
|
|
|
|
|
|
|
// Parse lines.
|
|
|
|
|
std::string line;
|
2022-08-16 14:44:38 +02:00
|
|
|
std::ifstream infile(std::string{timing_filepath});
|
2017-03-22 08:23:46 -07:00
|
|
|
while (std::getline(infile, line)) {
|
|
|
|
|
if (line.empty())
|
|
|
|
|
continue;
|
|
|
|
|
timing.push_back(parse_line(line));
|
|
|
|
|
}
|
|
|
|
|
infile.close();
|
|
|
|
|
|
|
|
|
|
return timing;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-16 14:44:38 +02:00
|
|
|
void SaveTiming(absl::string_view timing_filepath,
|
2017-03-22 08:23:46 -07:00
|
|
|
rtc::ArrayView<const Turn> timing) {
|
2022-08-16 14:44:38 +02:00
|
|
|
std::ofstream outfile(std::string{timing_filepath});
|
2017-06-15 03:49:57 -07:00
|
|
|
RTC_CHECK(outfile.is_open());
|
2017-03-22 08:23:46 -07:00
|
|
|
for (const Turn& turn : timing) {
|
2018-01-22 14:18:28 +01:00
|
|
|
outfile << turn.speaker_name << " " << turn.audiotrack_file_name << " "
|
|
|
|
|
<< turn.offset << " " << turn.gain << std::endl;
|
2017-03-22 08:23:46 -07:00
|
|
|
}
|
|
|
|
|
outfile.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace conversational_speech
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|