fix(audio): defer and coalesce role switch notices
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Run firmware timeout/round functions on host with scripted RTOS and transport."""
|
||||
"""Run timeout, round and role-notice scheduling with scripted RTOS and transport."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
@@ -27,7 +27,13 @@ harness = r'''
|
||||
#include <string.h>
|
||||
typedef void *ql_mutex_t;
|
||||
static int g_mic_working, recording, shine_init, fota_start;
|
||||
enum { STATE_IDLE, STATE_RECORDING_WAIT_SOUND, STATE_RECORDING_ACTIVE, STATE_WAITING_COMMAND };
|
||||
static int tts_playing, tts_play_status, audio_packet_type, no_speech_timeout;
|
||||
static int power_down_status, sleeping, vad_state;
|
||||
static int queue_failure, last_queue_type;
|
||||
static char last_queue_url[256];
|
||||
static int get_sleep_mode(void) { return sleeping; }
|
||||
static int vad_audio_get_state(void) { return vad_state; }
|
||||
static int queued, disconnected, flags_reset, mutex_locked, player_mq_couter, vad_starts;
|
||||
static uint64_t now;
|
||||
static unsigned int gSequenceNumber;
|
||||
@@ -42,8 +48,14 @@ static uint64_t hal_os_up_time_ms(void) { return now; }
|
||||
static void vad_set_speech_timeout_flag(int value) { no_speech_timeout = value; }
|
||||
static void vad_reset_conversation_flags(void) { no_speech_timeout = 0; flags_reset++; }
|
||||
static int build_random_tts_error_url(char *p, size_t n) { (void)p; (void)n; return 1; }
|
||||
static void add_file_to_play_player_queue(char *p, int type) { (void)p; assert(type == 3); queued++; }
|
||||
static void vad_start_func(void) { vad_starts++; recording = 1; g_mic_working = 0; }
|
||||
static int add_file_to_play_player_queue(char *p, int type) {
|
||||
assert(type == 3 || type == 5);
|
||||
if (queue_failure) return -1;
|
||||
queued++; player_mq_couter++; last_queue_type = type;
|
||||
snprintf(last_queue_url, sizeof(last_queue_url), "%s", p);
|
||||
return 0;
|
||||
}
|
||||
static void vad_start_func(void) { vad_starts++; recording = 1; vad_state = STATE_RECORDING_WAIT_SOUND; g_mic_working = 0; }
|
||||
static void app_play_tips_file(int n) { (void)n; assert(0); }
|
||||
static int conversation_try_begin(void);
|
||||
static void talkingq_ws_disconnect(void) {
|
||||
@@ -54,7 +66,7 @@ static void talkingq_ws_disconnect(void) {
|
||||
static int sendRecordingAudioPacket(AudioPacket *p) { assert(p->packetType == 2); return end_result; }
|
||||
'''
|
||||
harness += source[state_start:state_end]
|
||||
for name in ['conversation_try_begin', 'sendEndPacket', 'conversation_check_timeout', 'conversation_accept_voice_message', 'conversation_finish_startup_prompt', 'conversation_find_session_id']:
|
||||
for name in ['conversation_try_begin', 'sendEndPacket', 'conversation_check_timeout', 'conversation_accept_voice_message', 'conversation_finish_startup_prompt', 'conversation_find_session_id', 'role_notice_is_url', 'role_notice_start_locked', 'role_notice_poll_locked', 'app_role_notice_handle_url', 'app_role_notice_before_finish', 'role_notice_finished']:
|
||||
harness += function(name)
|
||||
harness += r'''
|
||||
static void reset(void) {
|
||||
@@ -62,6 +74,9 @@ static void reset(void) {
|
||||
conversation_round = wait_round = sender_round = 0;
|
||||
conversation_wait = WAIT_NONE; timeout_action_busy = round_response_received = 0;
|
||||
queued = disconnected = flags_reset = no_speech_timeout = mutex_locked = 0;
|
||||
power_down_status = sleeping = queue_failure = 0; vad_state = STATE_IDLE;
|
||||
role_notice_pending = role_notice_playing = role_notice_consumed = 0;
|
||||
role_notice_round = 0; last_queue_type = 0; last_queue_url[0] = 0;
|
||||
now = 1000; end_result = 0; player_mq_couter = vad_starts = 0; active_session_valid = 0; startup_start_ms = 0; tts_playing = 0;
|
||||
}
|
||||
int main(void) {
|
||||
@@ -126,7 +141,73 @@ int main(void) {
|
||||
assert(conversation_try_begin() == 0);
|
||||
now += 30001; player_mq_couter = 1; conversation_check_timeout(); assert(g_mic_working);
|
||||
player_mq_couter = 0; recording = 1; conversation_check_timeout(); assert(g_mic_working);
|
||||
puts("PASS: late backend error admission, prompt completion with queued audio, stale prompt, failed playback, stalled-startup recovery; no-speech prompt, new-round cancellation, ignored recording keys, END deadline, stale rounds, early reply, send failure, timeout/key race, auto-listening");
|
||||
/* The exact resource alone is routed; unrelated notices retain original path. */
|
||||
reset();
|
||||
assert(!app_role_notice_handle_url("http://host/assets/audio/card.mp3"));
|
||||
assert(!app_role_notice_handle_url("http://host/assets/audio/switch_role.mp3.extra"));
|
||||
assert(!role_notice_is_url("http://host/other/switch_role.mp3"));
|
||||
assert(!queued);
|
||||
/* No speech: retain one notice until tts_error + optional local fallback ends. */
|
||||
reset(); recording = 1; vad_state = STATE_RECORDING_WAIT_SOUND;
|
||||
assert(app_role_notice_handle_url("http://host/assets/audio/switch_role.mp3"));
|
||||
assert(!queued && role_notice_pending);
|
||||
recording = 0; vad_state = STATE_WAITING_COMMAND; conversation_wait = WAIT_NO_SPEECH;
|
||||
assert(app_role_notice_before_finish() && !queued);
|
||||
conversation_wait = WAIT_NONE; player_mq_couter = 1; no_speech_timeout = 1;
|
||||
assert(app_role_notice_before_finish() && !queued);
|
||||
player_mq_couter = 0;
|
||||
assert(app_role_notice_before_finish() && queued == 1 && last_queue_type == 5);
|
||||
assert(no_speech_timeout == 1); /* Error flag never becomes auto-listening. */
|
||||
assert(app_role_notice_before_finish() && queued == 1);
|
||||
player_mq_couter = 0; role_notice_finished(conversation_round, 0);
|
||||
assert(!app_role_notice_before_finish() && no_speech_timeout == 1);
|
||||
/* Speech: zero insertion while uploading/waiting or between reply segments. */
|
||||
reset(); recording = 1; vad_state = STATE_RECORDING_ACTIVE;
|
||||
app_role_notice_handle_url("http://host/assets/audio/switch_role.mp3");
|
||||
recording = 0; vad_state = STATE_WAITING_COMMAND; conversation_wait = WAIT_REPLY;
|
||||
assert(app_role_notice_before_finish() && !queued);
|
||||
conversation_wait = WAIT_NONE; tts_playing = 1;
|
||||
assert(app_role_notice_before_finish() && !queued);
|
||||
tts_playing = 0; player_mq_couter = 2;
|
||||
assert(app_role_notice_before_finish() && !queued);
|
||||
player_mq_couter = 0;
|
||||
assert(app_role_notice_before_finish() && queued == 1);
|
||||
role_notice_finished(conversation_round, 0); player_mq_couter = 0;
|
||||
assert(!app_role_notice_before_finish() && no_speech_timeout == 0);
|
||||
/* Repeated switches produce one latest URL at the end, never six entries. */
|
||||
reset(); vad_state = STATE_WAITING_COMMAND; tts_playing = 1;
|
||||
for (int n = 0; n < 6; n++) {
|
||||
char url[128]; snprintf(url, sizeof(url), "http://host/assets/audio/switch_role.mp3?v=%d", n);
|
||||
assert(app_role_notice_handle_url(url)); assert(!queued);
|
||||
}
|
||||
tts_playing = 0;
|
||||
assert(app_role_notice_before_finish() && queued == 1);
|
||||
assert(strstr(last_queue_url, "v=5"));
|
||||
app_role_notice_handle_url("http://host/assets/audio/switch_role.mp3");
|
||||
assert(queued == 1 && !role_notice_pending);
|
||||
role_notice_finished(conversation_round, 0); player_mq_couter = 0;
|
||||
app_role_notice_handle_url("http://host/assets/audio/switch_role.mp3");
|
||||
assert(queued == 1 && !app_role_notice_before_finish());
|
||||
/* Idle plays promptly; playback/queue failure releases completion too. */
|
||||
reset(); app_role_notice_handle_url("http://host/assets/audio/switch_role.mp3");
|
||||
assert(queued == 1); player_mq_couter = 0;
|
||||
role_notice_finished(conversation_round, -1); assert(!app_role_notice_before_finish());
|
||||
reset(); queue_failure = 1;
|
||||
app_role_notice_handle_url("http://host/assets/audio/switch_role.mp3");
|
||||
assert(!queued && !app_role_notice_before_finish());
|
||||
/* Accepted restart/force-stop cancels notice; no replay into next round. */
|
||||
reset(); vad_state = STATE_WAITING_COMMAND; tts_playing = 1;
|
||||
app_role_notice_handle_url("http://host/assets/audio/switch_role.mp3");
|
||||
assert(conversation_try_begin() == 0 && !role_notice_pending);
|
||||
reset(); recording = 1; app_role_notice_handle_url("http://host/assets/audio/switch_role.mp3");
|
||||
conversation_cancel_wait(); assert(!role_notice_pending && !role_notice_playing);
|
||||
for (int mode = 0; mode < 3; mode++) {
|
||||
reset(); vad_state = STATE_WAITING_COMMAND;
|
||||
app_role_notice_handle_url("http://host/assets/audio/switch_role.mp3");
|
||||
fota_start = mode == 0; power_down_status = mode == 1; sleeping = mode == 2;
|
||||
assert(!app_role_notice_before_finish() && !role_notice_pending && !queued);
|
||||
}
|
||||
puts("PASS: role notices: silent/speech end, latest-only coalescing, idle, failure, restart/OTA/shutdown/sleep isolation; late backend error admission, prompt completion with queued audio, stale prompt, failed playback, stalled-startup recovery; no-speech prompt, new-round cancellation, ignored recording keys, END deadline, stale rounds, early reply, send failure, timeout/key race, auto-listening");
|
||||
}
|
||||
'''
|
||||
with tempfile.TemporaryDirectory(prefix='banban-timeout-') as directory:
|
||||
|
||||
Reference in New Issue
Block a user