TextGrid_extensions.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef _TextGrid_extensions_h_
  2. #define _TextGrid_extensions_h_
  3. /* TextGrid_extensions.h
  4. *
  5. * Copyright (C) 1993-2018 David Weenink
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /*
  21. djmw 20020516 GPL header
  22. djmw 20120418 Latest modification
  23. */
  24. #include "TextGrid.h"
  25. autoTextGrid TextGrid_readFromTIMITLabelFile (MelderFile file, bool phnFile);
  26. /*
  27. Read TIMIT label file with the following structure:
  28. samplenumber1 samplenumber2 label1
  29. samplenumber3 samplenumber4 label2
  30. ...
  31. samplenumber2n-1 samplenumber2n labeln
  32. The first tier of TextGrid will contain the TIMIT labels.
  33. If phnFile == true, the second tier will contain the translation of the
  34. TIMIT labels into IPA labels.
  35. For the translation from sample number to time a default sampling
  36. frequency of 16000 Hz is assumed.
  37. */
  38. autoDaata TextGrid_TIMITLabelFileRecognizer (integer nread, const char *header, MelderFile file);
  39. /*
  40. There are two types of TIMIT label files. One with phonetic labels, these
  41. files have '.phn' as file extension. The other contains word labels and has
  42. '.wrd' as extension. Since these extensions are only valid on the CDROM we can
  43. not use them for filetype recognition. Both TIMIT label files do not have a
  44. self-describing format. For filetype recognition we make use of the fact that
  45. both files are text files and always have three items on each line: two numbers
  46. followed by a string. The numbers increase in a monotone way.
  47. The recognizer only checks the first two lines and it tests whether
  48. 0 <= number[1] < number[2] <= number[3] < number[4]
  49. (A number of .wrd files do not obey the monotonocity constraint for
  50. number[4] and number[5] !)
  51. The decision whether it is a .phn or .wrd file is:
  52. .phn if string[1] == 'h#' AND string[2] is a TIMIT phonetic label
  53. .wrd if (string[1] == 'h#' AND string[2] is a valid word) OR
  54. string[1] and string[2] are both valid words.
  55. A valid word is a string with contains the lowercase characters [a-z] and ['].
  56. */
  57. autoTextGrid TextGrids_merge (TextGrid grid1, TextGrid grid2);
  58. /*
  59. Merge two textGrids.
  60. The new domain will be:
  61. [min(grid1->xmin, grid2->xmin), max(grid1->xmax, grid2->xmax)].
  62. This implies that for the resulting TextGrid each interval tier will have
  63. one or two extra intervals if the domains of the two TextGrids are not equal,
  64. */
  65. void TextGrid_extendTime (TextGrid me, double delta_time, int position);
  66. /*
  67. Extend the begin-time (delta_time<0) or end-time (delta_time>0).
  68. For Point-tiers only the domain will be extended.
  69. Interval tiers will have a new (empty) interval at the start or the end.
  70. */
  71. void TextGrid_setTierName (TextGrid me, integer itier, conststring32 newName);
  72. void TextTier_changeLabels (TextTier me, integer from, integer to, conststring32 search, conststring32 replace, bool use_regexp, integer *nmatches, integer *nstringmatches);
  73. void IntervalTier_changeLabels (IntervalTier me, integer from, integer to, conststring32 search, conststring32 replace, bool use_regexp, integer *nmatches, integer *nstringmatches);
  74. void IntervalTier_removeBoundariesBetweenIdenticallyLabeledIntervals (IntervalTier me, conststring32 label);
  75. void IntervalTier_cutIntervalsOnLabelMatch (IntervalTier me, conststring32 label);
  76. void IntervalTier_cutIntervals_minimumDuration (IntervalTier me, conststring32 label, double minimumDuration);
  77. void TextGrid_changeLabels (TextGrid me, integer tier, integer from, integer to, conststring32 search, conststring32 replace, bool use_regexp, integer *nmatches, integer *nstringmatches);
  78. /* Set the start/end time to a smaller/larger value.
  79. * If mark is null, only times are changed
  80. * If mark != null, mark the previous start/end time
  81. * For a TextTier this involves adding a point with the marker
  82. * For an IntervalTier this involves adding a new interval
  83. */
  84. void IntervalTier_setLaterEndTime (IntervalTier me, double xmax, conststring32 mark);
  85. void IntervalTier_setEarlierStartTime (IntervalTier me, double xmin, conststring32 mark);
  86. void IntervalTier_moveBoundary (IntervalTier me, integer interval, bool atStart, double newTime);
  87. void TextTier_setLaterEndTime (TextTier me, double xmax, conststring32 mark);
  88. void TextTier_setEarlierStartTime (TextTier me, double xmin, conststring32 mark);
  89. void TextGrid_setEarlierStartTime (TextGrid me, double xmin, conststring32 intervalMark, conststring32 pointMark);
  90. void TextGrid_setLaterEndTime (TextGrid me, double xmax, conststring32 intervalMark, conststring32 pointMark);
  91. // Precondition: if (preserveTimes) { my xmax <= thy xmin }
  92. // Postcondition: my xmin preserved
  93. void IntervalTiers_append_inplace (IntervalTier me, IntervalTier thee, bool preserveTimes);
  94. void TextTiers_append_inplace (TextTier me, TextTier thee, bool preserveTimes);
  95. void TextGrids_append_inplace (TextGrid me, TextGrid thee, bool preserveTimes);
  96. autoTextGrid TextGrids_to_TextGrid_appendContinuous (OrderedOf<structTextGrid>* me, bool preserveTimes);
  97. double TextGrid_getTotalDurationOfIntervalsWhere (TextGrid me, integer tierNumber, kMelder_string which, conststring32 criterion);
  98. #endif /* _TextGrid_extensions_h_ */