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)
Let’s keep the conversation in one place (on the ticket). Then you can update this post when we get to the solution.