Skip to content

feat: add POST /infer/voice endpoint for text-to-speech audio [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH] - #573

Open
waterWang wants to merge 2 commits into
mergeos-bounties:masterfrom
waterWang:feat/infer-voice-api
Open

feat: add POST /infer/voice endpoint for text-to-speech audio [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]#573
waterWang wants to merge 2 commits into
mergeos-bounties:masterfrom
waterWang:feat/infer-voice-api

Conversation

@waterWang

Copy link
Copy Markdown

FastAPI: POST /infer/voice endpoint

Adds text-to-speech audio endpoints to the Loru API.

Changes

src/loru/api/app.py:

  • Added VoiceBody Pydantic model (text + language fields)
  • Added POST /infer/voice — converts text to speech and returns audio metadata
  • Added POST /infer/voice/file — returns the WAV audio file directly
  • Added FileResponse import for audio file streaming

tests/test_api.py:

  • test_infer_voice — verifies audio metadata response
  • test_infer_voice_empty_text — validates 422 on empty text
  • test_infer_voice_file — verifies WAV file response with headers

API

POST /infer/voice
{"text": "Hello world", "language": "en"}

Response:
{
  "ok": true,
  "text": "Hello world",
  "audio_path": "/tmp/.../voice.wav",
  "audio_exists": true,
  "audio_size_bytes": 12345,
  "tts_backend": "OfflineStubTTS",
  "duration_sec": 1.5
}

Design

  • Uses the existing get_default_tts() from loru.voice.tts — supports all TTS backends
  • OfflineStubTTS generates a real playable WAV (tone, not silence)
  • Both endpoints work without any external dependencies beyond the [api] extras
  • POST /infer/voice/file returns a proper FileResponse with audio/wav content type

Fixes #10

Wallet: FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH

wangye and others added 2 commits July 25, 2026 17:55
…geos-bounties#10)

Adds:
- POST /infer/voice endpoint accepting sequence frames → returns audio path
- Test coverage for voice endpoint (valid request, missing frames)
- Test coverage for /infer/text missing frames edge case
- OpenAPI tags match existing endpoints

Testing: 5 tests pass with TestClient
  ✓ test_health
  ✓ test_sentence
  ✓ test_voice
  ✓ test_voice_no_frames
  ✓ test_infer_text_no_frames

[FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]
Adds two new FastAPI endpoints to the Loru API:
- `POST /infer/voice` — accepts JSON {text, language} and returns audio metadata
- `POST /infer/voice/file` — returns the WAV audio file directly

Uses the configured TTS backend (OfflineStubTTS / Pyttsx3TTS / EdgeTTS)
via `get_default_tts()`.

Fixes mergeos-bounties#10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[50 MRG] FastAPI: POST /infer/text and /infer/voice

1 participant