v84: revert прокси — DPI режет multipart на lang.kube5s.ru (408), ffmpeg убран
This commit is contained in:
Vendored
+1
-1
@@ -776,7 +776,7 @@ async function doCompare(blob, originalText, duration) {
|
|||||||
<script>
|
<script>
|
||||||
// ---------- Глобальные переменные и инициализация ----------
|
// ---------- Глобальные переменные и инициализация ----------
|
||||||
const GROQ_API_KEY = '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';
|
const GROQ_API_KEY = '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';
|
||||||
const VERSION = 'v83';
|
const VERSION = 'v84';
|
||||||
|
|
||||||
let mediaRecorder, audioChunks = [], userAudioBlob = null, ttsText = '';
|
let mediaRecorder, audioChunks = [], userAudioBlob = null, ttsText = '';
|
||||||
let isRecording = false, isAnalyzing = false, micAnalyser = null, micAnimId = null;
|
let isRecording = false, isAnalyzing = false, micAnalyser = null, micAnimId = null;
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
// ---------- Глобальные переменные и инициализация ----------
|
// ---------- Глобальные переменные и инициализация ----------
|
||||||
const GROQ_API_KEY = '';
|
const GROQ_API_KEY = '';
|
||||||
const VERSION = 'v83';
|
const VERSION = 'v84';
|
||||||
|
|
||||||
let mediaRecorder, audioChunks = [], userAudioBlob = null, ttsText = '';
|
let mediaRecorder, audioChunks = [], userAudioBlob = null, ttsText = '';
|
||||||
let isRecording = false, isAnalyzing = false, micAnalyser = null, micAnimId = null;
|
let isRecording = false, isAnalyzing = false, micAnalyser = null, micAnimId = null;
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from flask import Flask, request, Response
|
from flask import Flask, request, Response
|
||||||
import requests
|
import requests
|
||||||
import subprocess
|
|
||||||
import tempfile
|
|
||||||
import os
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
GROQ_BASE = "https://api.groq.com"
|
GROQ_BASE = "https://api.groq.com"
|
||||||
@@ -24,11 +21,6 @@ def proxy(subpath):
|
|||||||
hdrs = {}
|
hdrs = {}
|
||||||
if request.headers.get("Authorization"):
|
if request.headers.get("Authorization"):
|
||||||
hdrs["Authorization"] = request.headers["Authorization"]
|
hdrs["Authorization"] = request.headers["Authorization"]
|
||||||
|
|
||||||
# Trim 0.2s from audio before sending to Whisper (server-side ffmpeg)
|
|
||||||
if subpath == "v1/audio/transcriptions" and request.method == "POST":
|
|
||||||
return proxy_transcription(url, hdrs)
|
|
||||||
|
|
||||||
if request.headers.get("Content-Type"):
|
if request.headers.get("Content-Type"):
|
||||||
hdrs["Content-Type"] = request.headers["Content-Type"]
|
hdrs["Content-Type"] = request.headers["Content-Type"]
|
||||||
r = requests.request(request.method, url, headers=hdrs,
|
r = requests.request(request.method, url, headers=hdrs,
|
||||||
@@ -37,48 +29,5 @@ def proxy(subpath):
|
|||||||
out["Content-Type"] = r.headers.get("Content-Type", "application/json")
|
out["Content-Type"] = r.headers.get("Content-Type", "application/json")
|
||||||
return Response(r.iter_content(8192), status=r.status_code, headers=out)
|
return Response(r.iter_content(8192), status=r.status_code, headers=out)
|
||||||
|
|
||||||
def proxy_transcription(url, hdrs):
|
|
||||||
audio = request.files.get('file') if request.files else None
|
|
||||||
if not audio:
|
|
||||||
hdrs["Content-Type"] = request.headers.get("Content-Type", "")
|
|
||||||
r = requests.post(url, headers=hdrs, data=request.get_data(), timeout=60)
|
|
||||||
out = dict(CORS)
|
|
||||||
out["Content-Type"] = r.headers.get("Content-Type", "application/json")
|
|
||||||
return Response(r.iter_content(8192), status=r.status_code, headers=out)
|
|
||||||
|
|
||||||
with tempfile.NamedTemporaryFile(suffix='.webm', delete=False) as tmp_in:
|
|
||||||
audio.save(tmp_in)
|
|
||||||
tmp_in_path = tmp_in.name
|
|
||||||
|
|
||||||
tmp_out_path = tmp_in_path + '.wav'
|
|
||||||
|
|
||||||
try:
|
|
||||||
subprocess.run([
|
|
||||||
'ffmpeg', '-y', '-ss', '0.2',
|
|
||||||
'-i', tmp_in_path,
|
|
||||||
'-f', 'wav', tmp_out_path
|
|
||||||
], check=True, capture_output=True, timeout=15)
|
|
||||||
|
|
||||||
files = {'file': ('audio.wav', open(tmp_out_path, 'rb'), 'audio/wav')}
|
|
||||||
data = {}
|
|
||||||
if request.form.get('model'):
|
|
||||||
data['model'] = request.form['model']
|
|
||||||
if request.form.get('language'):
|
|
||||||
data['language'] = request.form['language']
|
|
||||||
|
|
||||||
r = requests.post(url, headers=hdrs, data=data, files=files, timeout=60)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"[trim] ffmpeg failed: {e}, forwarding original")
|
|
||||||
hdrs["Content-Type"] = request.headers.get("Content-Type", "")
|
|
||||||
r = requests.post(url, headers=hdrs, data=request.get_data(), timeout=60)
|
|
||||||
finally:
|
|
||||||
os.unlink(tmp_in_path)
|
|
||||||
if os.path.exists(tmp_out_path):
|
|
||||||
os.unlink(tmp_out_path)
|
|
||||||
|
|
||||||
out = dict(CORS)
|
|
||||||
out["Content-Type"] = r.headers.get("Content-Type", "application/json")
|
|
||||||
return Response(r.iter_content(8192), status=r.status_code, headers=out)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="127.0.0.1", port=8765)
|
app.run(host="127.0.0.1", port=8765)
|
||||||
|
|||||||
Reference in New Issue
Block a user