feat(chat): add SiliconFlow ASR for agent voice input
Replace Web Speech API with MediaRecorder upload to POST /api/speech/transcribe, calling SenseVoice via the existing GJL API credentials. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
445763e144
commit
8f69131872
9 files changed
+350
-215
No files matched your search
@@ -0,0 +1,40 @@
|
||||
"""
|
||||
Speech transcription API — forwards audio to SiliconFlow ASR.
|
||||
"""
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
from app.auth_jwt import get_current_user
|
||||
from app.errors import UnauthorizedError, ValidationError, ServiceUnavailableError
|
||||
from app.services.speech_asr import SpeechAsrService
|
||||
|
||||
speech_bp = Blueprint('speech', __name__)
|
||||
|
||||
|
||||
@speech_bp.route('/transcribe', methods=['POST'])
|
||||
def transcribe_audio():
|
||||
user = get_current_user()
|
||||
if not user:
|
||||
raise UnauthorizedError('Unauthorized')
|
||||
|
||||
uploaded = request.files.get('audio') or request.files.get('file')
|
||||
if not uploaded or not uploaded.filename:
|
||||
raise ValidationError('audio file is required')
|
||||
|
||||
audio_bytes = uploaded.read()
|
||||
filename = uploaded.filename or 'recording.webm'
|
||||
content_type = uploaded.content_type or ''
|
||||
|
||||
try:
|
||||
SpeechAsrService.validate_upload(filename, len(audio_bytes))
|
||||
except ValueError as exc:
|
||||
raise ValidationError(str(exc)) from exc
|
||||
|
||||
try:
|
||||
text, model = SpeechAsrService.transcribe(audio_bytes, filename, content_type)
|
||||
except RuntimeError as exc:
|
||||
raise ServiceUnavailableError(str(exc)) from exc
|
||||
|
||||
return jsonify({
|
||||
'text': text,
|
||||
'model': model,
|
||||
})
|
||||
Reference in new issue
Block a user