當前位置: 首頁>>代碼示例>>Python>>正文


Python pysrt.open方法代碼示例

本文整理匯總了Python中pysrt.open方法的典型用法代碼示例。如果您正苦於以下問題:Python pysrt.open方法的具體用法?Python pysrt.open怎麽用?Python pysrt.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pysrt的用法示例。


在下文中一共展示了pysrt.open方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: extract_labels

# 需要導入模塊: import pysrt [as 別名]
# 或者: from pysrt import open [as 別名]
def extract_labels(srt, samples):
    subs = pysrt.open(srt)
    labels = np.zeros(samples)
    for sub in subs:
        start = timeToPos(sub.start)
        end = timeToPos(sub.end)+1
        for i in range(start, end):
            if i < len(labels):
                labels[i] = 1

    return labels 
開發者ID:tympanix,項目名稱:subsync,代碼行數:13,代碼來源:train_data.py

示例2: __init__

# 需要導入模塊: import pysrt [as 別名]
# 或者: from pysrt import open [as 別名]
def __init__(self, media, path):
        self.media = media
        self.path = path
        self.subs = pysrt.open(self.path, encoding=self._find_encoding()) 
開發者ID:tympanix,項目名稱:subsync,代碼行數:6,代碼來源:media.py

示例3: _find_encoding

# 需要導入模塊: import pysrt [as 別名]
# 或者: from pysrt import open [as 別名]
def _find_encoding(self):
        data = None
        with open(self.path, "rb") as f:
            data = f.read()
        det = chardet.detect(data)
        return det.get("encoding") 
開發者ID:tympanix,項目名稱:subsync,代碼行數:8,代碼來源:media.py

示例4: write_to_file

# 需要導入模塊: import pysrt [as 別名]
# 或者: from pysrt import open [as 別名]
def write_to_file(self, output_path: Opt[str] = None):
        util.touch(output_path)
        sub_rip_file = pysrt.open(output_path, encoding='utf-8')

        for index, sub in enumerate(self.subtitles):
            start_time = pysrt.SubRipTime.from_ordinal(sub.start_time * 1000)
            end_time = pysrt.SubRipTime.from_ordinal(sub.end_time * 1000)
            next_sub = pysrt.SubRipItem(index=index, text=sub.text, start=start_time, end=end_time)
            sub_rip_file.append(next_sub)

        sub_rip_file.save(output_path, encoding='utf-8')

        return output_path 
開發者ID:scherroman,項目名稱:mugen,代碼行數:15,代碼來源:subtitles.py

示例5: generateDatasets

# 需要導入模塊: import pysrt [as 別名]
# 或者: from pysrt import open [as 別名]
def generateDatasets(train_files, cut_data, len_mfcc, step_mfcc, hop_len, freq):
    
    X, Y = [], []
    
    for tf in train_files:

        train_data, labels = generateSingleDataset(tf, cut_data, len_mfcc, step_mfcc, hop_len, freq)
                
        X.append(train_data)
        Y.append(labels)
        
    X = np.concatenate(X)
    Y = np.concatenate(Y)
        
    if cut_data:
        filename = STORE_DIR + 'dataset_CUT_' + str(freq) + '_' + str(hop_len) + '_' + str(len_mfcc) + '_' + str(step_mfcc) + '_' + str(X.shape[0]) + '_' + str(X.shape[1]) + '_' + str(X.shape[2]) + '.pickle'
    else:
        filename = STORE_DIR + 'dataset_' + str(freq) + '_' + str(hop_len) + '_' + str(len_mfcc) + '_' + str(step_mfcc) + '_' + str(X.shape[0]) + '_' + str(X.shape[1]) + '_' + str(X.shape[2]) + '.pickle'
    print filename
    with open(filename, 'w') as f:
        pickle.dump([X, Y], f)
        
    return X, Y


# Generate a dataset from all available files 
開發者ID:AlbertoSabater,項目名稱:subtitle-synchronization,代碼行數:28,代碼來源:audio_converter.py

示例6: sotreResults

# 需要導入模塊: import pysrt [as 別名]
# 或者: from pysrt import open [as 別名]
def sotreResults(results, v):
# %%
    import pickle
    
    with open('test_results_'+v+'.pickle', 'w') as f:
        pickle.dump(results, f)


# %% 

# Plot stored training statistics. Look for the best model 
開發者ID:AlbertoSabater,項目名稱:subtitle-synchronization,代碼行數:13,代碼來源:train_nets.py

示例7: load_srt

# 需要導入模塊: import pysrt [as 別名]
# 或者: from pysrt import open [as 別名]
def load_srt(srt_dir, srt_cache_path):
    """
    return: A python dict, the keys are the video names, the entries are lists,
            each contains all the text from a .srt file
    sub_times are the start time of the sentences.
    """
    if os.path.exists(srt_cache_path):
        print("Found srt data cache, loading ...")
        return load_json(srt_cache_path)

    print("Loading srt files from %s ..." % srt_dir)
    srt_paths = glob.glob(os.path.join(srt_dir, "*.srt"))
    name2sub_text = {}
    name2sub_time = {}
    for i in tqdm(range(len(srt_paths))):
        subs = pysrt.open(srt_paths[i], encoding="iso-8859-1")
        if len(subs) == 0:
            subs = pysrt.open(srt_paths[i])

        text_list = []
        sub_time_list = []
        for j in range(len(subs)):
            cur_sub = subs[j]
            cur_str = cur_sub.text
            cur_str = "(<UNKNAME>:)" + cur_str if cur_str[0] != "(" else cur_str
            cur_str = cur_str.replace("\n", " ")
            text_list.append(cur_str)
            sub_time_list.append(
                60 * cur_sub.start.minutes + cur_sub.start.seconds + 0.001 * cur_sub.start.milliseconds)

        key_str = os.path.splitext(os.path.basename(srt_paths[i]))[0]
        name2sub_text[key_str] = text_list
        name2sub_time[key_str] = sub_time_list
    srt_data = {"sub_text": name2sub_text, "sub_time": name2sub_time}
    save_json(srt_data, srt_cache_path)
    return srt_data 
開發者ID:jayleicn,項目名稱:TVQA,代碼行數:38,代碼來源:preprocessing.py

示例8: find_summary_regions

# 需要導入模塊: import pysrt [as 別名]
# 或者: from pysrt import open [as 別名]
def find_summary_regions(srt_filename, duration=30, language="english"):
    """ Find important sections

    Args:
        srt_filename(str): Name of the SRT FILE
        duration(int): Time duration
        language(str): Language of subtitles (default to English)

    Returns:
        list: segment of subtitles as "summary"

    """
    srt_file = pysrt.open(srt_filename)

    enc = chardet.detect(open(srt_filename, "rb").read())['encoding']
    srt_file = pysrt.open(srt_filename, encoding=enc)

    # generate average subtitle duration
    subtitle_duration = time_regions(
        map(srt_segment_to_range, srt_file)) / len(srt_file)
    # compute number of sentences in the summary file
    n_sentences = duration / subtitle_duration
    summary = summarize(srt_file, n_sentences, language)
    total_time = time_regions(summary)
    too_short = total_time < duration
    if too_short:
        while total_time < duration:
            n_sentences += 1
            summary = summarize(srt_file, n_sentences, language)
            total_time = time_regions(summary)
    else:
        while total_time > duration:
            n_sentences -= 1
            summary = summarize(srt_file, n_sentences, language)
            total_time = time_regions(summary)
    return summary 
開發者ID:OpenGenus,項目名稱:vidsum,代碼行數:38,代碼來源:sum.py

示例9: parseSrtAndSetItems

# 需要導入模塊: import pysrt [as 別名]
# 或者: from pysrt import open [as 別名]
def parseSrtAndSetItems(self):
        try:
            self.items = pysrt.open(self.filePath, encoding='utf8')
            return 0
        except:
            return 11 
開發者ID:suifengtec,項目名稱:subtitle-translator,代碼行數:8,代碼來源:serviceFile.py


注:本文中的pysrt.open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。