Feature/voice preview - #1
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR implements a premium Voice Preview feature in Awaaz, allowing users to listen to any selected voice (default or custom) before starting a full audiobook generation job. Previews are accessible from both the audiobook Generation Form and the Settings Modal.
Key Additions & Improvements
POST /api/v1/backends/{name}/previewendpoint. It synthesizes a short WAV snippet, converts it to MP3 using FFmpeg, and streams it back. Temporary audio files are cleaned up immediately post-stream using FastAPIBackgroundTasksto avoid disk leaks.useVoicePreviewhook in the frontend to manage audio playback, load state transitions, and ensure resource cleanup (object URL revocation) when components unmount..field-span { grid-column: span 2; }instyles.cssto fix vertical layout misalignment in the form fields.Files Changed
Backend
src/awaaz/api.py— Added/backends/{name}/previewendpoint andPreviewRequestvalidation.tests/test_api_preview.py— Created unit tests for preview successes, invalid engines, text length limits, and adapter errors.tests/test_api_contract.py— Verified preview route is successfully generated in OpenAPI schema.Frontend
frontend/src/api/client.ts— AddedpreviewVoicefetch client wrapper.frontend/src/hooks/useVoicePreview.ts— Created a custom playback hook.frontend/src/components/VoiceSelector.tsx— Styled selector dropdown row to include loading/playing buttons.frontend/src/components/GenerationForm.tsx— Wired hook, added custom preview text inputs, and handled state overrides.frontend/src/components/SettingsModal.tsx— Added voice preview support for default voice settings.frontend/src/styles.css— Added layout styling, play/stop button designs, and animation keyframes.frontend/src/__tests__/api.test.ts— Added fetch API mocks to verify the preview client function.Verification & Testing
Automated Tests
uv run pytest(43 passed).npm run test(5 passed).