From ab3bb98676c6b283c55c76377ddec8767e7dd882 Mon Sep 17 00:00:00 2001 From: Renato Rosa Date: Wed, 19 Aug 2026 21:01:31 -0300 Subject: [PATCH] Atualizar app/app.py --- app/app.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/app/app.py b/app/app.py index aec3b82..c5fd748 100644 --- a/app/app.py +++ b/app/app.py @@ -341,8 +341,63 @@ def search(): db.close() return jsonify(results) +from pywhispercpp.model import Model +@app.route("/api/audio/transcribe/", methods=["POST"]) +@login_required +@require_capability("can_use_audio") +def transcribe(cid): + # Initialize the model (automatically downloads 'base.en' if not present) + model = Model('base.en', print_realtime=False, print_progress=False) + + + file = request.files.get("file") + if not file: + return jsonify({"error": "No audio file"}), 400 + path = f"/data/audio-{uuid.uuid4()}.wav" + file.save(path) + # Example using whisper (pseudo-code) + # result = whisper.transcribe(path) + # text = result["text"] + + # Transcribe your audio file (must be 16kHz WAV format) + segments = model.transcribe(path) + + # Print the text results + for segment in segments: + print(f"[{segment.t0} -> {segment.t1}]: {segment.text}") + + text = "Transcribed text placeholder" + + db = SessionLocal() + msg = Message( + id=str(uuid.uuid4()), + conversation_id=cid, + role="user", + content=text, + ) + db.add(msg) + db.commit() + db.close() + + return jsonify({"status": "ok", "text": text}) + +from gtts import gTTS + +@app.route("/api/audio/synthesize/", methods=["POST"]) +@login_required +@require_capability("can_use_audio") +def synthesize(cid): + text = request.json.get("text", "") + if not text: + return jsonify({"error": "No text"}), 400 + + tts = gTTS(text=text, lang="en") + path = f"/data/tts-{uuid.uuid4()}.mp3" + tts.save(path) + + return send_file(path, mimetype="audio/mpeg", as_attachment=False) # ***