<commit_before>'''
Functions for reading/writing/manipulating textgrid files

Created on Apr 15, 2013

@author: timmahrt
'''

import re
import copy
import io
import wave
from collections import namedtuple

from praatio.utilities import utils

INTERVAL_TIER = "IntervalTier"
POINT_TIER = "TextTier"
MIN_INTERVAL_LENGTH = 0.00000001  # Arbitrary threshold

Interval = namedtuple('Interval', ['start', 'stop', 'label']) # interval entry
Point = namedtuple('Point', ['time', 'label']) # point entry


def _getWavDuration(wavFN):
    "For internal use.  See praatio.audioio.WavQueryObj() for general use."
    audiofile = wave.open(wavFN, "r")
    params = audiofile.getparams()
    framerate = params[2]
    nframes = params[3]
    duration = float(nframes) / framerate
    
    return duration


def _fillInBlanks(tier, blankLabel="", startTime=None, endTime=None):
    '''
    Fills in the space between intervals with empty space
    <commit_msg>REFACTOR: Changed 'stop' to 'end' in named tuple.<commit_after>'''
Functions for reading/writing/manipulating textgrid files

Created on Apr 15, 2013

@author: timmahrt
'''

import re
import copy
import io
import wave
from collections import namedtuple

from praatio.utilities import utils

INTERVAL_TIER = "IntervalTier"
POINT_TIER = "TextTier"
MIN_INTERVAL_LENGTH = 0.00000001  # Arbitrary threshold

Interval = namedtuple('Interval', ['start', 'end', 'label']) # interval entry
Point = namedtuple('Point', ['time', 'label']) # point entry


def _getWavDuration(wavFN):
    "For internal use.  See praatio.audioio.WavQueryObj() for general use."
    audiofile = wave.open(wavFN, "r")
    params = audiofile.getparams()
    framerate = params[2]
    nframes = params[3]
    duration = float(nframes) / framerate
    
    return duration


def _fillInBlanks(tier, blankLabel="", startTime=None, endTime=None):
    '''
    Fills in the space between intervals with empty space
    
{'fraction_non_alphanumeric': 0.10805194805194805, 'fraction_numerical': 0.017662337662337664, 'mean_word_length': 4.456090651558074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1251934', 'n_tokens_mistral': 634, 'n_tokens_neox': 597, 'n_words': 183}