-
Notifications
You must be signed in to change notification settings - Fork 731
fix(gradio): reapply audio volume persistence with sane default #697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c6faf1e
Fix Gradio audio volume persistence and playback reset
1larity d803b45
Stop playback on regenerate without remounting audio
1larity 0dd1f2a
fix(ui-audio): seed sane default volume when storage is missing
1larity 7a34990
fix(pr680): address review findings and seed first-run volume defaults
1larity 4249748
fix(build): include audio_player_preferences.js in wheel
1larity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
acestep/ui/gradio/events/results/audio_playback_updates.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """Audio playback update helpers for Gradio result players. | ||
|
|
||
| These helpers standardize audio update payloads so playback always rewinds to | ||
| the start of the track when a new value is assigned. | ||
| """ | ||
|
|
||
| from typing import Any, Optional | ||
|
|
||
|
|
||
| def build_audio_slot_update( | ||
| gr_module: Any, | ||
| audio_path: Optional[str], | ||
| *, | ||
| label: Optional[str] = None, | ||
| interactive: Optional[bool] = None, | ||
| ) -> Any: | ||
| """Build an audio slot update that always rewinds playback to 0. | ||
|
|
||
| Args: | ||
| gr_module: Module/object exposing ``update(**kwargs)``. | ||
| audio_path: Filepath for the audio component, or ``None`` to clear. | ||
| label: Optional component label override. | ||
| interactive: Optional component interactivity override. | ||
|
|
||
| Returns: | ||
| The framework-specific update object returned by ``gr_module.update``. | ||
| """ | ||
| update_kwargs = { | ||
| "value": audio_path, | ||
| "playback_position": 0, | ||
| } | ||
| if label is not None: | ||
| update_kwargs["label"] = label | ||
| if interactive is not None: | ||
| update_kwargs["interactive"] = interactive | ||
| return gr_module.update(**update_kwargs) |
64 changes: 64 additions & 0 deletions
64
acestep/ui/gradio/events/results/audio_playback_updates_test.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """Unit tests for audio_playback_updates helpers.""" | ||
|
|
||
| import importlib.util | ||
| from pathlib import Path | ||
| import unittest | ||
|
|
||
|
|
||
| def _load_module(): | ||
| """Load the target module directly by file path for isolated testing.""" | ||
| module_path = Path(__file__).with_name("audio_playback_updates.py") | ||
| spec = importlib.util.spec_from_file_location("audio_playback_updates", module_path) | ||
| module = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(module) # type: ignore[union-attr] | ||
| return module | ||
|
|
||
|
|
||
| _MODULE = _load_module() | ||
| build_audio_slot_update = _MODULE.build_audio_slot_update | ||
|
|
||
|
|
||
| class _FakeGr: | ||
| """Minimal Gradio-like stub exposing ``update``.""" | ||
|
|
||
| @staticmethod | ||
| def update(**kwargs): | ||
| """Return kwargs for direct assertion in tests.""" | ||
| return kwargs | ||
|
|
||
|
|
||
| class AudioPlaybackUpdatesTests(unittest.TestCase): | ||
| """Behavior tests for audio playback update builders.""" | ||
|
|
||
| def test_build_audio_slot_update_sets_value_and_rewinds(self): | ||
| """Success path: slot update should carry path and playback reset.""" | ||
| sample_path = "sample.flac" | ||
| result = build_audio_slot_update( | ||
| _FakeGr, | ||
| sample_path, | ||
| label="Sample 1 (Ready)", | ||
| interactive=False, | ||
| ) | ||
| self.assertEqual(result["value"], sample_path) | ||
| self.assertEqual(result["playback_position"], 0) | ||
| self.assertEqual(result["label"], "Sample 1 (Ready)") | ||
| self.assertFalse(result["interactive"]) | ||
|
|
||
| def test_build_audio_slot_update_clear_path_rewinds(self): | ||
| """Regression path: clearing a slot should still force playback to start.""" | ||
| result = build_audio_slot_update(_FakeGr, None) | ||
| self.assertEqual(result["value"], None) | ||
| self.assertEqual(result["playback_position"], 0) | ||
|
|
||
| def test_build_audio_slot_update_without_optional_flags_preserves_defaults(self): | ||
| """Non-target behavior: no label/interactivity overrides unless explicitly passed.""" | ||
| sample_path = "sample.flac" | ||
| result = build_audio_slot_update(_FakeGr, sample_path) | ||
| self.assertEqual(result["value"], sample_path) | ||
| self.assertEqual(result["playback_position"], 0) | ||
| self.assertNotIn("label", result) | ||
| self.assertNotIn("interactive", result) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.