0

Flaskと whisper_timestamped ライブラリを使用して音声ファイルを書き起こそうとしているのですが、メモリ関連の問題が発生しています。アプリを Render にデプロイし、/transcribe エンドポイントを使って音声の書き起こしリクエストを行いました。しかし、毎回以下のエラーが出ます。

[ERROR] Worker (pid:67) was sent SIGKILL! Perhaps out of memory?

おそらくリクエストを処理するワーカーのプロセスがメモリの問題で終了するためエラーが発生しています。ライブラリまたはモデルがメモリを大量に消費するため、アプリがメモリ割り当てを超過しているのではないかと思うのですが、解決策はないでしょうか。

ご教示・アドバイスのほど、お願いいたします。

現状のコード:

from flask import Flask, request, jsonify
import whisper_timestamped
import tempfile
import os

app = Flask(__name__)

@app.route('/')
def hello():
    name = "Hello World"
    return name

@profile
def transcribe_audio(audio_file_path):
    model = whisper_timestamped.load_model("base")
    audio = whisper_timestamped.load_audio(audio_file_path)
    result = whisper_timestamped.transcribe(model, audio, language="en")
    transcribed_text = result["text"]
    word_timestamps = []
    for segment in result["segments"]:
        for word in segment["words"]:
            word_timestamps.append({"word": word["text"], "startTime": word["start"], "endTime": word["end"]})

    return {"transcribedText": transcribed_text, "wordTimestamps": word_timestamps}

@app.route('/transcribe', methods=['POST'])
@profile
def transcribe():
    if 'audio' not in request.files:
        return jsonify({'error': 'No audio file provided.'}), 400

    audio_file = request.files['audio']

    # Create a temporary directory to store the audio file
    temp_dir = tempfile.mkdtemp()

    # Save the audio file temporarily to the temporary directory
    temp_audio_path = os.path.join(temp_dir, "temp_audio.wav")
    audio_file.save(temp_audio_path)

    result = transcribe_audio(temp_audio_path)

    # Remove the temporary audio file and directory after transcription
    os.remove(temp_audio_path)
    os.rmdir(temp_dir)

    return jsonify(result), 200

if __name__ == "__main__":
    app.run(debug=True)
1

1 件の回答 1

1

少し調べた程度の情報ですが、参考までに。

Render.com はフリープランだとメモリが 512MB しか使えないそうです。また、該当のライブラリは GPU を使う方法も用意されているようなので、それなりにリソースを必要とするのではないでしょうか?

まずはローカル環境などでどの程度のリソースが必要となるのかを見極めた上で、Render.com で (より上位の) 有償プランに切り替える、もしくは読み込むデータやモデルのサイズを減らす、などが現実的な対応策になるかと思います。

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。