Home

Awesome

textgrid.hpp - a C++ TextGrid parser / writer

CircleCI MIT License

Introduction

textgrid.hpp is a C++ library for interacting with Praat TextGrid files.

It has the following features:

Notes on Praat and TextGrid file format:

Examples

Now, there are only 3 examples to read from stdin and write to stdout.

I will write how to use TextGrid, Tier, IntervalTier, PointTier, Interval, Point objects.

Read TextGrid file from std::cin and Write to std::cout with operators

void ReadAndWriteViaStdio() {
  textgrid::TextGrid text_grid;
  try {
    std::cin >> text_grid;
    std::cout << text_grid;
  } catch (const textgrid::Exception& e) {
    std::cerr << e.what() << std::endl;
  }
}

Read TextGrid file from std::cin and Write to std::cout in 1 line

void ReadAndWriteViaStdioInOneLine() {
  try {
    textgrid::Parser(std::cin).Parse().Accept(textgrid::Writer(std::cout));
  } catch (const textgrid::Exception& e) {
    std::cerr << e.what() << std::endl;
  }
}

Read TextGrid file from std::cin and Write to std::cout step by step

int ReadAndWriteStepByStep(std::istream& in,
                           std::ostream& out,
                           std::ostream& err,
                           bool in_short = false) {
  try {
    textgrid::Parser parser(in);
    textgrid::TextGrid text_grid = parser.Parse();
    if (in_short) {
      textgrid::ShortWriter writer(out);
      text_grid.Accept(writer);
    } else {
      textgrid::Writer writer(out);
      text_grid.Accept(writer);
    }
    return 0;
  } catch (const textgrid::Exception& e) {
    err << e.what() << std::endl;
    return -1;
  }
}

See also in the examples/textgrid_print.cpp.

Build and Test

Build example commands in the examples directory

$ make

Test the style of codes by cpplint

$ make check-style

or

$ make check-style-by-cpplint

Fix the style of codes by clang-format

$ make check-style-by-clang-format

Build and run tests

$ make check

Todo

License

This is licensed under the MIT License.

Copyright (c) 2019, Eiichiro Iwata. All rights reserved.