Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: webrtc/modules/audio_processing/test/conversational_speech/timing.cc

Issue 2750353002: Conversational speech tool: timing model with data access. (Closed)
Patch Set: deps fixed Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/audio_processing/test/conversational_speech/timing.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
16 #include "webrtc/base/array_view.h"
17 #include "webrtc/base/stringencode.h"
18
19 namespace webrtc {
20 namespace test {
21 namespace conversational_speech {
22
23 bool Turn::operator==(const Turn &b) const {
24 return b.speaker_name == speaker_name &&
25 b.audiotrack_file_name == audiotrack_file_name &&
26 b.offset == offset;
27 }
28
29 std::vector<Turn> LoadTiming(const std::string& timing_filepath) {
30 // Line parser.
31 auto parse_line = [](const std::string& line) {
32 std::vector<std::string> fields;
33 rtc::split(line, ' ', &fields);
34 RTC_CHECK_EQ(fields.size(), 3);
35 return Turn(fields[0], fields[1], std::atol(fields[2].c_str()));
36 };
37
38 // Init.
39 std::vector<Turn> timing;
40
41 // Parse lines.
42 std::string line;
43 std::ifstream infile(timing_filepath);
44 while (std::getline(infile, line)) {
45 if (line.empty())
46 continue;
47 timing.push_back(parse_line(line));
48 }
49 infile.close();
50
51 return timing;
52 }
53
54 void SaveTiming(const std::string& timing_filepath,
55 rtc::ArrayView<const Turn> timing) {
56 std::ofstream outfile(timing_filepath);
57 // TODO(alessio): check if file open for writing.
58 for (const Turn& turn : timing) {
59 outfile << turn.speaker_name << " " << turn.audiotrack_file_name
60 << " " << turn.offset << std::endl;
61 }
62 outfile.close();
63 }
64
65 } // namespace conversational_speech
66 } // namespace test
67 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/test/conversational_speech/timing.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698