Fixing Piper test.
This commit is contained in:
@@ -199,13 +199,13 @@ async def run_test(
|
|||||||
#
|
#
|
||||||
# Down frames
|
# Down frames
|
||||||
#
|
#
|
||||||
received_down_frames: Sequence[Frame] = []
|
received_down_frames: list[Frame] = []
|
||||||
if expected_down_frames is not None:
|
while not received_down.empty():
|
||||||
while not received_down.empty():
|
frame = await received_down.get()
|
||||||
frame = await received_down.get()
|
if not isinstance(frame, EndFrame) or not send_end_frame:
|
||||||
if not isinstance(frame, EndFrame) or not send_end_frame:
|
received_down_frames.append(frame)
|
||||||
received_down_frames.append(frame)
|
|
||||||
|
|
||||||
|
if expected_down_frames is not None:
|
||||||
down_frames_printed = "["
|
down_frames_printed = "["
|
||||||
for frame in received_down_frames:
|
for frame in received_down_frames:
|
||||||
down_frames_printed += f"{frame.__class__.__name__}, "
|
down_frames_printed += f"{frame.__class__.__name__}, "
|
||||||
@@ -225,12 +225,12 @@ async def run_test(
|
|||||||
#
|
#
|
||||||
# Up frames
|
# Up frames
|
||||||
#
|
#
|
||||||
received_up_frames: Sequence[Frame] = []
|
received_up_frames: list[Frame] = []
|
||||||
if expected_up_frames is not None:
|
while not received_up.empty():
|
||||||
while not received_up.empty():
|
frame = await received_up.get()
|
||||||
frame = await received_up.get()
|
received_up_frames.append(frame)
|
||||||
received_up_frames.append(frame)
|
|
||||||
|
|
||||||
|
if expected_up_frames is not None:
|
||||||
print("received UP frames =", received_up_frames)
|
print("received UP frames =", received_up_frames)
|
||||||
print("expected UP frames =", expected_up_frames)
|
print("expected UP frames =", expected_up_frames)
|
||||||
|
|
||||||
|
|||||||
@@ -77,28 +77,36 @@ async def test_run_piper_tts_success(aiohttp_client):
|
|||||||
TTSSpeakFrame(text="Hello world."),
|
TTSSpeakFrame(text="Hello world."),
|
||||||
]
|
]
|
||||||
|
|
||||||
expected_returned_frames = [
|
|
||||||
AggregatedTextFrame,
|
|
||||||
TTSStartedFrame,
|
|
||||||
TTSAudioRawFrame,
|
|
||||||
TTSAudioRawFrame,
|
|
||||||
TTSAudioRawFrame,
|
|
||||||
TTSAudioRawFrame,
|
|
||||||
TTSAudioRawFrame,
|
|
||||||
TTSAudioRawFrame,
|
|
||||||
TTSAudioRawFrame,
|
|
||||||
TTSAudioRawFrame,
|
|
||||||
TTSStoppedFrame,
|
|
||||||
TTSTextFrame,
|
|
||||||
]
|
|
||||||
|
|
||||||
frames_received = await run_test(
|
frames_received = await run_test(
|
||||||
tts_service,
|
tts_service,
|
||||||
frames_to_send=frames_to_send,
|
frames_to_send=frames_to_send,
|
||||||
expected_down_frames=expected_returned_frames,
|
|
||||||
)
|
)
|
||||||
down_frames = frames_received[0]
|
down_frames = frames_received[0]
|
||||||
|
frame_types = [type(f) for f in down_frames]
|
||||||
|
|
||||||
|
# Verify key frames are present
|
||||||
|
assert AggregatedTextFrame in frame_types
|
||||||
|
assert TTSStartedFrame in frame_types
|
||||||
|
assert TTSStoppedFrame in frame_types
|
||||||
|
assert TTSTextFrame in frame_types
|
||||||
|
|
||||||
|
# Verify ordering: Started → audio → Stopped → Text
|
||||||
|
started_idx = frame_types.index(TTSStartedFrame)
|
||||||
|
stopped_idx = frame_types.index(TTSStoppedFrame)
|
||||||
|
text_idx = frame_types.index(TTSTextFrame)
|
||||||
|
assert started_idx < text_idx < stopped_idx, (
|
||||||
|
"Expected: TTSStartedFrame < TTSTextFrame < TTSStoppedFrame"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Frames between Started and Stopped must all be audio or text
|
||||||
|
for i in range(started_idx + 1, stopped_idx):
|
||||||
|
assert frame_types[i] in (TTSAudioRawFrame, TTSTextFrame), (
|
||||||
|
f"Unexpected frame type between Started and Stopped: {frame_types[i]}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# All audio frames have correct sample rate
|
||||||
audio_frames = [f for f in down_frames if isinstance(f, TTSAudioRawFrame)]
|
audio_frames = [f for f in down_frames if isinstance(f, TTSAudioRawFrame)]
|
||||||
|
assert len(audio_frames) >= 1, "Expected at least one audio frame"
|
||||||
for a_frame in audio_frames:
|
for a_frame in audio_frames:
|
||||||
assert a_frame.sample_rate == 24000, "Sample rate should match the default (24000)"
|
assert a_frame.sample_rate == 24000, "Sample rate should match the default (24000)"
|
||||||
|
|
||||||
@@ -128,7 +136,7 @@ async def test_run_piper_tts_error(aiohttp_client):
|
|||||||
TTSSpeakFrame(text="Error case.", append_to_context=False),
|
TTSSpeakFrame(text="Error case.", append_to_context=False),
|
||||||
]
|
]
|
||||||
|
|
||||||
expected_down_frames = [AggregatedTextFrame, TTSStoppedFrame, TTSTextFrame]
|
expected_down_frames = [AggregatedTextFrame, TTSStartedFrame, TTSTextFrame, TTSStoppedFrame]
|
||||||
|
|
||||||
expected_up_frames = [ErrorFrame]
|
expected_up_frames = [ErrorFrame]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user