OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/audio_processing/test/conversational_speech/timing.h" | |
12 | |
13 #include <fstream> | |
14 #include <iostream> | |
15 #include <utility> | |
16 | |
17 #include "webrtc/base/array_view.h" | |
18 #include "webrtc/base/stringencode.h" | |
19 | |
20 namespace webrtc { | |
21 namespace test { | |
22 namespace conversational_speech { | |
23 | |
24 bool Turn::operator==(const Turn &b) const { | |
25 return b.speaker_name == speaker_name && | |
26 b.audiotrack_file_name == audiotrack_file_name && | |
27 b.offset == offset; | |
28 } | |
29 | |
30 std::vector<Turn> LoadTiming(const std::string& timing_filepath) { | |
31 // Line parser. | |
32 auto parse_line_ = [](const std::string& line) { | |
kwiberg-webrtc
2017/03/22 12:06:39
No trailing underscore, since this isn't a member
AleBzk
2017/03/22 15:26:21
Done.
| |
33 std::vector<std::string> fields; | |
34 rtc::split(line, ' ', &fields); | |
35 RTC_CHECK_EQ(fields.size(), 3); | |
36 return Turn(fields[0], fields[1], std::atol(fields[2].c_str())); | |
37 }; | |
38 | |
39 // Init. | |
40 std::vector<Turn> timing; | |
41 | |
42 // Parse lines. | |
43 std::string line; | |
44 std::ifstream infile(timing_filepath); | |
45 while (std::getline(infile, line)) { | |
46 if (line.empty()) | |
47 continue; | |
48 timing.push_back(parse_line_(line)); | |
49 } | |
50 infile.close(); | |
51 | |
52 return timing; | |
53 } | |
54 | |
55 void SaveTiming(const std::string& timing_filepath, | |
56 const std::vector<Turn>& timing) { | |
57 std::ofstream outfile(timing_filepath); | |
58 // TODO(alessio): check if file open for writing. | |
59 for (const Turn& turn : timing) { | |
60 outfile << turn.speaker_name << " " << turn.audiotrack_file_name | |
61 << " " << turn.offset << std::endl; | |
62 } | |
63 outfile.close(); | |
64 } | |
65 | |
66 } // namespace conversational_speech | |
67 } // namespace test | |
68 } // namespace webrtc | |
OLD | NEW |