youngtsai commited on
Commit
e950bce
1 Parent(s): 938aee2

def format_seconds_to_time(seconds):

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -49,6 +49,12 @@ def docx_to_text(file):
49
  doc = Document(file)
50
  return "\n".join([para.text for para in doc.paragraphs])
51
 
 
 
 
 
 
 
52
  def process_youtube_link(link):
53
  # 使用 YouTube API 获取逐字稿
54
  # 假设您已经获取了 YouTube 视频的逐字稿并存储在变量 `transcript` 中
@@ -60,7 +66,9 @@ def process_youtube_link(link):
60
 
61
  formatted_transcript = ""
62
  for entry in transcript:
63
- line = f"时间: {entry['start']} 秒, 持续: {entry['duration']} 秒, 文本: {entry['text']}\n"
 
 
64
  formatted_transcript += line
65
 
66
  # 确保返回与 UI 组件预期匹配的输出
 
49
  doc = Document(file)
50
  return "\n".join([para.text for para in doc.paragraphs])
51
 
52
+ def format_seconds_to_time(seconds):
53
+ """将秒数格式化为 分:秒 的形式"""
54
+ minutes = int(seconds // 60)
55
+ seconds = int(seconds % 60)
56
+ return f"{minutes:02}:{seconds:02}"
57
+
58
  def process_youtube_link(link):
59
  # 使用 YouTube API 获取逐字稿
60
  # 假设您已经获取了 YouTube 视频的逐字稿并存储在变量 `transcript` 中
 
66
 
67
  formatted_transcript = ""
68
  for entry in transcript:
69
+ start_time = format_seconds_to_time(entry['start'])
70
+ end_time = format_seconds_to_time(entry['start'] + entry['duration'])
71
+ line = f"----時間: {start_time} ~ {end_time}----\n{entry['text']}\n"
72
  formatted_transcript += line
73
 
74
  # 确保返回与 UI 组件预期匹配的输出