fix: recordings keep only what was played, newest waiting request kept, video pages opened play
- Playback tells the worker how much of each request was played (tts_played); the worker keeps a spoken answer's recording only that far (an answer stopped mid-way no longer keeps its unheard rest, and is marked stopped); nothing played or never reported: no file. - Old recording day folders are also removed with the first recording of each new day. - response.interrupt off, latest: a request whose final comes after a newer one's is replaced instead of replacing it. - botBrowser presses play on a page's paused main player also after open, not only after a click. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,9 @@ pub trait TtsBackend {
|
||||
/// Send text for request `id`; false when the worker is not connected (the request then fails).
|
||||
fn tts(&self, id: &str, text: &str, more: bool) -> bool;
|
||||
fn tts_cancel(&self, id: &str);
|
||||
/// Request `id` ended after `played` of its sentences started playing (the worker's recording
|
||||
/// keeps that much, voice_worker.spec.md, "Recordings").
|
||||
fn tts_played(&self, id: &str, played: u32, cancelled: bool);
|
||||
}
|
||||
|
||||
/// Plays one PCM clip at a time; its owner calls `Playback::clip_ended()` when the clip finishes.
|
||||
@@ -125,8 +128,7 @@ impl<B: TtsBackend, S: ClipSink> Playback<B, S> {
|
||||
self.sink.stop();
|
||||
}
|
||||
crate::debug_log!("play", "cancel id={} played={}", r.id, r.played);
|
||||
self.events.push(PlaybackEvent::End(PlaybackEnd { id: r.id, played: r.played, cancelled: true,
|
||||
failed: false }));
|
||||
self.ended(PlaybackEnd { id: r.id, played: r.played, cancelled: true, failed: false });
|
||||
self.pump();
|
||||
}
|
||||
|
||||
@@ -172,13 +174,18 @@ impl<B: TtsBackend, S: ClipSink> Playback<B, S> {
|
||||
self.sink.stop();
|
||||
}
|
||||
for r in &stopped {
|
||||
self.events.push(PlaybackEvent::End(PlaybackEnd { id: r.id.clone(), played: r.played, cancelled: true,
|
||||
failed: false }));
|
||||
self.ended(PlaybackEnd { id: r.id.clone(), played: r.played, cancelled: true, failed: false });
|
||||
}
|
||||
crate::debug_log!("play", "stop requests={} was_playing={was_playing}", stopped.len());
|
||||
stopped.len()
|
||||
}
|
||||
|
||||
/// A request ended: tell the worker how much of it was played, then the owner.
|
||||
fn ended(&mut self, end: PlaybackEnd) {
|
||||
self.backend.tts_played(&end.id, end.played, end.cancelled);
|
||||
self.events.push(PlaybackEvent::End(end));
|
||||
}
|
||||
|
||||
fn pump(&mut self) {
|
||||
while !self.playing {
|
||||
let Some(head) = self.queue.front_mut() else { return };
|
||||
@@ -204,8 +211,7 @@ impl<B: TtsBackend, S: ClipSink> Playback<B, S> {
|
||||
}
|
||||
let r = self.queue.pop_front().expect("head exists");
|
||||
crate::debug_log!("play", "said id={} sentences={} failed={}", r.id, r.played, r.failed);
|
||||
self.events.push(PlaybackEvent::End(PlaybackEnd { id: r.id, played: r.played, cancelled: false,
|
||||
failed: r.failed }));
|
||||
self.ended(PlaybackEnd { id: r.id, played: r.played, cancelled: false, failed: r.failed });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,6 +227,7 @@ mod tests {
|
||||
cancelled: Vec<String>,
|
||||
played: Vec<String>,
|
||||
stops: usize,
|
||||
reported: Vec<(String, u32, bool)>,
|
||||
}
|
||||
#[derive(Clone, Default)]
|
||||
struct Fake(Rc<RefCell<Log>>);
|
||||
@@ -232,6 +239,9 @@ mod tests {
|
||||
fn tts_cancel(&self, id: &str) {
|
||||
self.0.borrow_mut().cancelled.push(id.into());
|
||||
}
|
||||
fn tts_played(&self, id: &str, played: u32, cancelled: bool) {
|
||||
self.0.borrow_mut().reported.push((id.into(), played, cancelled));
|
||||
}
|
||||
}
|
||||
impl ClipSink for Fake {
|
||||
fn play(&mut self, pcm: Vec<u8>) {
|
||||
@@ -274,6 +284,25 @@ mod tests {
|
||||
assert!(!p.busy());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_worker_is_told_how_much_of_each_request_was_played() {
|
||||
let (mut p, f) = setup();
|
||||
let a = p.say("하나. 둘.", false);
|
||||
p.audio(&a, 0, b("a0"));
|
||||
p.audio(&a, 1, b("a1"));
|
||||
p.done(&done(&a, false));
|
||||
p.clip_ended();
|
||||
p.clip_ended();
|
||||
let c = p.say("셋. 넷.", false);
|
||||
p.audio(&c, 0, b("c0"));
|
||||
p.audio(&c, 1, b("c1"));
|
||||
p.done(&done(&c, false));
|
||||
p.cancel(&c); // stopped while its first sentence played
|
||||
let d = p.say("다섯.", false);
|
||||
p.stop(); // stopped before any sound
|
||||
assert_eq!(f.0.borrow().reported, vec![(a, 2, false), (c, 1, true), (d, 0, true)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requests_play_in_the_order_they_were_made() {
|
||||
let (mut p, f) = setup();
|
||||
|
||||
Reference in New Issue
Block a user