[BugFix] Fix local media access for diffusion speech (#6622)
Signed-off-by: zhuhh97 <zhuhonghan@huawei.com>
This commit is contained in:
1 parent
034af1f657
commit
f584729f24
4 files changed
+121
-15
No files matched your search
@@ -739,7 +739,11 @@ async def test_pure_diffusion_app_state_key_snapshot(monkeypatch) -> None:
|
||||
)
|
||||
|
||||
state = State()
|
||||
await api_server.omni_init_app_state(engine, state, _minimal_args())
|
||||
await api_server.omni_init_app_state(
|
||||
engine,
|
||||
state,
|
||||
_minimal_args(),
|
||||
)
|
||||
|
||||
_assert_app_state_snapshot(
|
||||
state,
|
||||
@@ -750,6 +754,55 @@ async def test_pure_diffusion_app_state_key_snapshot(monkeypatch) -> None:
|
||||
assert state.diffusion_engine is engine
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pure_diffusion_speech_forwards_media_access_args(monkeypatch) -> None:
|
||||
stage = SimpleNamespace(engine_args={})
|
||||
engine = _FakeEngineClient(stage_configs=[stage])
|
||||
speech_kwargs = {}
|
||||
|
||||
def _for_diffusion_factory(label: str):
|
||||
@classmethod
|
||||
def _factory(cls, *args, **kwargs):
|
||||
return _marker(label)
|
||||
|
||||
return _factory
|
||||
|
||||
@classmethod
|
||||
def _speech_factory(cls, *args, **kwargs):
|
||||
speech_kwargs.update(kwargs)
|
||||
return _marker("speech")
|
||||
|
||||
monkeypatch.setattr(api_server, "get_stage_type", lambda _cfg: "diffusion")
|
||||
monkeypatch.setattr(api_server.OmniOpenAIServingChat, "for_diffusion", _for_diffusion_factory("chat"))
|
||||
monkeypatch.setattr(api_server.OmniOpenAIServingChatBatch, "for_diffusion", _for_diffusion_factory("chat_batch"))
|
||||
monkeypatch.setattr(
|
||||
api_server.OmniOpenAIServingAudioGenerate,
|
||||
"for_diffusion",
|
||||
_for_diffusion_factory("audio_generate"),
|
||||
)
|
||||
monkeypatch.setattr(api_server.OmniOpenAIServingVideo, "for_diffusion", _for_diffusion_factory("video"))
|
||||
monkeypatch.setattr(api_server.OmniStreamingVideoOutputHandler, "__init__", lambda self, *a, **k: None)
|
||||
monkeypatch.setattr(api_server.OmniOpenAIServingSpeech, "for_diffusion", _speech_factory)
|
||||
monkeypatch.setattr(
|
||||
api_server.ServingRealtimeRobotOpenPI,
|
||||
"create_policy_server",
|
||||
classmethod(lambda cls, *a, **k: _marker("openpi")),
|
||||
)
|
||||
|
||||
state = State()
|
||||
await api_server.omni_init_app_state(
|
||||
engine,
|
||||
state,
|
||||
_minimal_args(
|
||||
allowed_local_media_path="/allowed/media",
|
||||
allowed_media_domains=["media.example.com"],
|
||||
),
|
||||
)
|
||||
|
||||
assert speech_kwargs["allowed_local_media_path"] == "/allowed/media"
|
||||
assert speech_kwargs["allowed_media_domains"] == ["media.example.com"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_multistage_app_state_key_snapshot(monkeypatch) -> None:
|
||||
"""Lock multi-stage ``app.state`` keys after init, including live vs None.
|
||||
|
||||
@@ -1245,6 +1245,46 @@ class TestTTSMethods:
|
||||
cache_key
|
||||
) == speech_server._make_ref_audio_artifact_cache_key(np.asarray(first[0], dtype=np.float32), 24000)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_diffusion_ref_audio_uses_media_access_config(
|
||||
self,
|
||||
mocker: MockerFixture,
|
||||
monkeypatch,
|
||||
tmp_path,
|
||||
):
|
||||
monkeypatch.setenv("SPEAKER_SAMPLES_DIR", str(tmp_path / "speakers"))
|
||||
connector = mocker.MagicMock()
|
||||
connector.fetch_audio_async = mocker.AsyncMock(return_value=(np.zeros(24000, dtype=np.float32), 24000))
|
||||
connector_cls = mocker.patch.object(
|
||||
serving_speech_module,
|
||||
"MediaConnector",
|
||||
return_value=connector,
|
||||
)
|
||||
media_dir = tmp_path / "media"
|
||||
media_dir.mkdir()
|
||||
ref_audio = media_dir / "reference.wav"
|
||||
ref_audio.write_bytes(b"v1")
|
||||
|
||||
server = OmniOpenAIServingSpeech.for_diffusion(
|
||||
diffusion_engine=mocker.MagicMock(),
|
||||
model_name="test-model",
|
||||
allowed_local_media_path=str(media_dir),
|
||||
allowed_media_domains=["media.example.com"],
|
||||
)
|
||||
try:
|
||||
first = await server._resolve_ref_audio(ref_audio.as_uri())
|
||||
ref_audio.write_bytes(b"v2-with-different-size")
|
||||
second = await server._resolve_ref_audio(ref_audio.as_uri())
|
||||
finally:
|
||||
server.shutdown()
|
||||
|
||||
connector_cls.assert_called_once_with(
|
||||
allowed_local_media_path=str(media_dir),
|
||||
allowed_media_domains=["media.example.com"],
|
||||
)
|
||||
assert first[2] != second[2]
|
||||
assert connector.fetch_audio_async.await_count == 2
|
||||
|
||||
# ── ref-audio cache key tests (static helper) ──
|
||||
|
||||
def test_local_file_cache_key_invalidation(self):
|
||||
|
||||
Reference in new issue
Block a user