• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/core/kernels/spectrogram_test_utils.h"
17 
18 #include "tensorflow/core/lib/core/errors.h"
19 #include "tensorflow/core/lib/core/status.h"
20 #include "tensorflow/core/platform/init_main.h"
21 #include "tensorflow/core/platform/logging.h"
22 
23 namespace tensorflow {
24 namespace wav {
25 
26 // This takes a CSV file representing an array of complex numbers, and saves out
27 // a version using a binary format to save space in the repository.
ConvertCsvToRaw(const string & input_filename)28 Status ConvertCsvToRaw(const string& input_filename) {
29   std::vector<std::vector<std::complex<double>>> input_data;
30   ReadCSVFileToComplexVectorOrDie(input_filename, &input_data);
31   const string output_filename = input_filename + ".bin";
32   if (!WriteComplexVectorToRawFloatFile(output_filename, input_data)) {
33     return errors::InvalidArgument("Failed to write raw float file ",
34                                    input_filename);
35   }
36   LOG(INFO) << "Wrote raw file to " << output_filename;
37   return Status::OK();
38 }
39 
40 }  // namespace wav
41 }  // namespace tensorflow
42 
main(int argc,char * argv[])43 int main(int argc, char* argv[]) {
44   tensorflow::port::InitMain(argv[0], &argc, &argv);
45   if (argc < 2) {
46     LOG(ERROR) << "You must supply a CSV file as the first argument";
47     return 1;
48   }
49   tensorflow::string filename(argv[1]);
50   tensorflow::Status status = tensorflow::wav::ConvertCsvToRaw(filename);
51   if (!status.ok()) {
52     LOG(ERROR) << "Error processing '" << filename << "':" << status;
53     return 1;
54   }
55   return 0;
56 }
57