feat(api): add OpenAI-compatible ASR transcription endpoint

- Implement POST /audio/transcriptions and /v1/audio/transcriptions
  endpoints for automatic speech recognition
- Add support for multipart/form-data audio file uploads
- Support multiple audio formats (wav, mp3, m4a, etc.)
- Implement language detection with 29 supported languages
- Return transcription text in OpenAI-compatible JSON format
- Add proper error handling and validation
- Include comprehensive tests for ASR functionality

refactor(api): restructure API modules and export MODEL

- Move API declarations to src/api/mod.rs
- Add ASR module and type definitions
- Export MODEL static for use in ASR module
- Mount ASR routes at both /audio and /v1/audio endpoints
This commit is contained in:
XiaoYang
2026-03-06 11:38:24 +08:00
parent 14ecd4676c
commit 63a89b0c96
6 changed files with 398 additions and 4 deletions
+4 -2
View File
@@ -632,8 +632,10 @@ pub(crate) async fn start_http_server(
builder = builder.mount("/chat", routes![api::chat]);
// /images/remove_background
builder = builder.mount("/images", routes![api::remove_background]);
// /audio/speech
builder = builder.mount("/audio", routes![api::speech]);
// /audio/speech and /audio/transcriptions (ASR transcription endpoint)
builder = builder.mount("/audio", routes![api::speech, api::transcriptions]);
// /v1/audio/transcriptions (OpenAI standard ASR transcription endpoint)
builder = builder.mount("/v1/audio", routes![api::transcriptions]);
// Health check and model info endpoints
builder = builder.mount("/", routes![api::health, api::models]);
// Shutdown endpoint