Python入門トップページ


目次

  1. 仮想環境を構築し,watchdog をインストールする
  2. Watchdog でフォルダを監視する
  3. 新しいファイルを検知する
  4. 検知した新しいファイルを待ち行列フォルダに移動する
  5. 文字起こし処理用のワーカープログラムのひな形を作成する
  6. ワーカープログラムを常駐化する
  7. フォルダ監視とワーカープログラムでパイプライン処理する
  8. 処理用フォルダを設置してそこで処理を行う
  9. ファイルサイズの変化を監視する
  10. サイズの大きなファイルのコピーに対応する
  11. タイムスタンプを表示する
  12. Subprocess で外部コマンドを起動する
  13. WhisperX の設定を行う
  14. ワーカープログラムで音声データからの文字起こしを実行する
  15. 文字起こし結果を完了用フォルダに移動する
  16. ログを保存し例外を処理する
  17. サブフォルダに結果を格納する
  18. Ollama をインストールする
  19. Python から Ollama にプロンプトを送る
  20. Ollama 処理を関数化する
  21. 文字起こしデータから議事録を作成する
  22. サイズの大きなテキストファイルにも対応する
  23. ワーカープログラムで文字起こし結果から議事録を生成する
  24. 議事録をマークダウンファイルに出力する
  25. 文字コードを強制的に指定する

フォルダ監視により,音声ファイルから文字起こしと議事録生成を自動化しよう

サイズの大きなテキストファイルにも対応する

前のページではサイズの小さなテキストデータでは動作したものの,巨大なテキストデータではコマンドが長くなりすぎるために失敗しました.ここではプロンプトをコマンドに含めないようにコードを修正します.

具体的には,次のとおりプロンプトを input 引数に渡しますことで解決します.

ollama.py
import subprocess

def ask_ollama(prompt):

    result = subprocess.run(
        ["ollama", "run", "qwen3:8b"],
        input=prompt,  # ここに書くと大きなファイルでも動く
        capture_output=True,
        text=True,
        encoding="utf-8"
    )

    return result.stdout


# with open("sample/voice-sample01.txt", encoding="utf-8") as f:
#     transcript = f.read()

with open("sample/voice-sample99.txt", encoding="utf-8") as f: # 巨大なテキストファイル
    transcript = f.read()

prompt = f"""
次の文字起こし結果から議事録を作成してください。

{transcript}
"""

minutes = ask_ollama(prompt)
print(minutes)

この修正によってサイズの大きなテキストファイルであっても処理できるようになりました.

(py313watchdog) PS C:\Users\rinsaka\Documents\python\watchdog> python ollama.py ⏎
Thinking...
Okay, I need to create a meeting minutes from the given transcript. Let me start by understanding the content. The speaker mentions the Bank of Japan's Governor Ueda giving a speech in Tokyo today, discussing the possibility of raising interest rates even if the Middle East situation remains uncertain. The BOJ is holding a policy meeting from the 15th to the 16th. Ueda mentioned that even with ongoing uncertainty in the Middle East, they might proceed with a rate hike.

First, I should structure the minutes with the date, location, attendees, and the main points discussed. Since the user didn't specify attendees, maybe I can note that it's a speech by the Governor, so the attendees would be the public or stakeholders. The main topics are the speech content and the upcoming policy meeting. I need to highlight Ueda's statement about potential rate hike despite Middle East tensions. Also, mention the dates of the policy meeting. Keep it concise and formal, using appropriate terminology. Make sure to note the key points clearly and accurately reflect the speaker's information without adding any extra details.
...done thinking.

**議事録**
**日時**:令和X年X月X日(火曜日)
**場所**:東京(都内)

**出席者**:
- 日銀総裁 上田 明(発表者)
- 外部関係者・メディア(※具体的な出席者名は未明記)

**議題**:
1. 中東情勢と金融政策の動向に関する発表
2. 金融政策決定会合の日程と今後の方向性

**議事内容**:
1. **発表内容**
   - 日銀総裁上田明は、都内で行われた講演において、中東情勢が不透明な状況が続く中でも、利上げの可能性を示唆しました。
   - 上田総裁は、経済の動向や物価上昇圧力など、多角的な視点を踏まえ、金融政策の見直しを検討していると強調。中東情勢の影響を過度に過小評価せず、適切な政策対応を求める姿勢を示しました。

2. **金融政策決定会合の日程**
   - 日銀は、令和X年X月15日から16日にかけて、金融政策決定会合を開催することを発表。
   - 会合では、物価動向、雇用市場の状況、国内外の経済指標などを踏まえた政策判断が行われる予定。

**次回の予定**:
- 金融政策決定会合の結果発表(X月X日)
- 総裁の今後の講演・発表のスケジュール(※未定)

**備考**:
- 中東情勢の影響を踏まえた金融政策の動向に注目が集まると予想される。
- 経済指標や国際情勢の変化に応じた柔軟な対応が求められるとの認識が示された。

---
※本議事録は、講演内容に基づく要約であり、公式発表とは異なる可能性があることをご了承ください。


(py313watchdog) PS C:\Users\rinsaka\Documents\python\watchdog>

次のページではここで作成した機能をワーカープログラムに追加して,自動的な処理ができるようにしましょう.

目次に戻る