vrewがいいので、書き出した情報を使ってwordのドキュメントを自動で作ります
AIにpythonのプログラムを作ってもらいました
プロンプト
フォルダーに画像、voice.txtがあります
voice.txtは下記のフォーマットです
NN:NN:NN 文字列
NN:NN:NN 時間です
画像はpngです
画像は1_N.pngです
#Nは連番です。voice.txtの行に対応しています
画像、voice.txtはoutputフォルダーに格納されています
これらを使ってwordの文書を作って、ダウンロードできるようにしてください
プログラムはpythonで作ってください
wordは右側に画像、左に文字列
ページに4枚の画像が入るようにしてください
出来上がったプログラム
import os
from docx import Document
from docx.shared import Inches
from PIL import Image
VOICE_FILE = "output/voice.txt"
IMAGE_DIR = "output"
OUTPUT_DOCX = "result.docx"
def read_voice_lines(path):
lines = []
with open(path, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if not line:
continue
lines.append(line)
return lines
def get_image_path(index):
filename = f"1_{index}.png"
path = os.path.join(IMAGE_DIR, filename)
return path if os.path.exists(path) else None
def add_text_and_image(table, row, text, image_path):
left_cell = table.cell(row, 0)
right_cell = table.cell(row, 1)
left_cell.text = text
if image_path:
# 画像サイズを調整(幅 2.5 インチ)
right_cell.paragraphs[0].add_run().add_picture(image_path, width=Inches(2.5))
def main():
voice_lines = read_voice_lines(VOICE_FILE)
doc = Document()
# 4 行 × 2 列(左:文字、右:画像)
ROWS_PER_PAGE = 4
for i, text in enumerate(voice_lines, start=1):
if (i - 1) % ROWS_PER_PAGE == 0:
# 新しいページに表を作成
if i != 1:
doc.add_page_break()
table = doc.add_table(rows=ROWS_PER_PAGE, cols=2)
table.autofit = False
row = (i - 1) % ROWS_PER_PAGE
image_path = get_image_path(i)
add_text_and_image(table, row, text, image_path)
doc.save(OUTPUT_DOCX)
print("Word ファイルを作成しました:", OUTPUT_DOCX)
if __name__ == "__main__":
main()
これが出力です
これって結構使えます
ちょっとしたものなら簡単に作成できます
教えている最中にスニッピングツールで録画して、vrewで処理、pythonでwordに出力
あっという間に出来上がります
