Get ngrams from a text
    Sourced from:
    https://gist.github.com/dannguyen/93c2c43f4e65328b85af

def get_ngrams(inputfile, n=1, use_transcript=False, use_vtt=False):
    '''
    Get ngrams from a text
    Sourced from:
    https://gist.github.com/dannguyen/93c2c43f4e65328b85af
    '''

    words = []
    if use_transcript:
        for s in audiogrep.convert_timestamps(inputfile):
            for w in s['words']:
                words.append(w[0])
    elif use_vtt:
        vtts = get_vtt_files(inputfile)
        for vtt in vtts:
            with open(vtt['vtt'], 'r') as infile:
                sentences = parse_auto_sub(infile.read())
            for s in sentences:
                for w in s['words']:
                    words.append(w['word'])
    else:
        text = ''
        srts = get_subtitle_files(inputfile)
        for srt in srts:
            lines = clean_srt(srt)
            if lines:
                for timespan in lines.keys():
                    line = lines[timespan].strip()
                    text += line + ' '

        words = re.split(r'[.?!,:\"]+\s*|\s+', text)

    ngrams = zip(*[words[i:] for i in range(n)])
    return ngrams