|
@@ -234,6 +234,33 @@ def call_anchor(fileName,avatar):
|
|
|
|
|
|
fr.close()
|
|
|
fw.close()
|
|
|
+def sentence_time_ratio(text,maxLen):
|
|
|
+
|
|
|
+ total_len = len(text)
|
|
|
+ if total_len > maxLen:
|
|
|
+ left_word = total_len % maxLen
|
|
|
+ times = int(math.ceil(total_len/maxLen))
|
|
|
+ if left_word < 5:
|
|
|
+ times+=1
|
|
|
+ sen_len = int(total_len/times)
|
|
|
+
|
|
|
+ time_ratio = [None]*times
|
|
|
+ sentences = [None]*times
|
|
|
+ print(times,',',total_len,",",sen_len)
|
|
|
+ for t in range(times):
|
|
|
+
|
|
|
+ sentences[t] = text[t*sen_len:t*sen_len+sen_len]
|
|
|
+ time_ratio[t] = len(sentences[t])/total_len
|
|
|
+ else:
|
|
|
+
|
|
|
+ time_ratio = [1]
|
|
|
+ sen_len = total_len
|
|
|
+ sentences = [text]
|
|
|
+
|
|
|
+ return sen_len, time_ratio, sentences
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
def parse_script(file_path,gt_list):
|
|
|
with open(file_path, 'r') as f:
|
|
|
raw_lines = [line.strip() for line in f]
|
|
@@ -256,40 +283,26 @@ def parse_script(file_path,gt_list):
|
|
|
script['stop'] = stop_sec
|
|
|
script['duration'] = abs(duration)
|
|
|
dict_list.append(script)
|
|
|
+ '''
|
|
|
+ for dic in dict_list:
|
|
|
+ print(dic)
|
|
|
+ '''
|
|
|
new_idx = 0
|
|
|
splitted_dict = []
|
|
|
-
|
|
|
for dic in dict_list:
|
|
|
- #螢幕寬度只能容納13個字
|
|
|
- if len(dic['content'])>13:
|
|
|
- times = math.ceil(len(dic['content'])/13)
|
|
|
- time_ratio = [None] *times
|
|
|
- left_words = len(dic['content'])%13
|
|
|
- for t in range(times):
|
|
|
- if t != (times-1):
|
|
|
- time_ratio[t] = 1 * dic['duration']/times
|
|
|
- else:
|
|
|
- time_ratio[t] = 1 * dic['duration'] / times
|
|
|
- for t in range(times):
|
|
|
- if True:
|
|
|
- #if time_ratio[t]>0.22:#about less than 3 words
|
|
|
- new_dic = {}
|
|
|
- new_dic['index'] = new_idx
|
|
|
- new_dic['content'] = dic['content'][t*13:t*13+13]
|
|
|
- start_plus = 0
|
|
|
- for t2 in range(t):
|
|
|
- start_plus += time_ratio[t2]
|
|
|
- new_dic['start'] = dic['start'] + start_plus+0.1
|
|
|
- new_dic['stop'] = new_dic['start']+time_ratio[t]
|
|
|
- new_dic['duration'] = time_ratio[t]-0.05
|
|
|
- splitted_dict.append(new_dic)
|
|
|
- new_idx+=1
|
|
|
- #else:
|
|
|
- # splitted_dict[new_idx-1]['content']+=dic['content']
|
|
|
- else:
|
|
|
- dic['index'] = new_idx
|
|
|
+ sen_len, time_ratio, sentences = sentence_time_ratio(dic['content'],13)
|
|
|
+ for s in range(len(sentences)):
|
|
|
+ new_dict = {}
|
|
|
+ new_dict['index'] = new_idx
|
|
|
+ start = dic['start']
|
|
|
+ for t in range(s):
|
|
|
+ start += (dic['duration']*time_ratio[t])
|
|
|
+ new_dict['start'] = start
|
|
|
+ new_dict['duration'] = dic['duration'] * time_ratio[s]
|
|
|
+ new_dict['content'] = sentences[s]
|
|
|
new_idx+=1
|
|
|
- splitted_dict.append(dic)
|
|
|
+ splitted_dict.append(new_dict)
|
|
|
+
|
|
|
return splitted_dict
|
|
|
def adjustSub_by_text_similarity(gts,gens):
|
|
|
adjusted = [None]*len(gens)
|