Skip to main content

VoiceService

Struct VoiceService 

Source
pub struct VoiceService {
    loader: Arc<dyn Fn() -> Result<Arc<dyn Engine>, String> + Send + Sync>,
    engine: Arc<Mutex<Option<Arc<dyn Engine>>>>,
    settings: VoiceSettings,
    sink: Arc<dyn AudioSink>,
    notes: Arc<dyn NoteDispatch>,
    seats: Arc<Mutex<HashMap<SessionSlot, Seat>>>,
    previews: Arc<Mutex<HashMap<SessionSlot, PreviewSlot>>>,
}
Expand description

The per-seat voice service. One render queue per seat, so a second say waits behind the first, and one engine for the whole process, loaded at boot and kept for the process’s life; a failed warm is retried by the first say.

Fields§

§loader: Arc<dyn Fn() -> Result<Arc<dyn Engine>, String> + Send + Sync>§engine: Arc<Mutex<Option<Arc<dyn Engine>>>>§settings: VoiceSettings§sink: Arc<dyn AudioSink>§notes: Arc<dyn NoteDispatch>§seats: Arc<Mutex<HashMap<SessionSlot, Seat>>>§previews: Arc<Mutex<HashMap<SessionSlot, PreviewSlot>>>

The previews one seat may have in flight: a held key updates the newest voice instead of queueing one render per press.

Implementations§

Source§

impl VoiceService

Source

pub fn new( loader: Arc<dyn Fn() -> Result<Arc<dyn Engine>, String> + Send + Sync>, settings: VoiceSettings, sink: Arc<dyn AudioSink>, notes: Arc<dyn NoteDispatch>, ) -> Self

Source

pub async fn say( &self, seat: &SessionSlot, text: String, ) -> Result<(), SayError>

Queue one utterance for seat. Answers once the first audio is rendered, so a named engine failure reaches the caller rather than disappearing into a playback queue.

Source

pub async fn preview( &self, seat: &SessionSlot, voice: String, ) -> Result<(), SayError>

Render one fixed line in voice on seat’s own stream, so a voice is heard before it is chosen. The seat’s speaker switch is the playback gate: nobody listening means nowhere to play.

One render loop per seat. While a preview renders, a second press replaces the pending voice instead of queueing another render, so the newest press is the one heard and a held key costs one render.

Source

fn settle_previews(&self, seat: &SessionSlot, generation: u64) -> Option<String>

End the loop generation owns and hand back the voice a later press left waiting. A newer loop’s flag and voice are its own, and neither is touched.

Source

fn restart_previews(&self, seat: &SessionSlot, voice: String) -> Option<u64>

Claim the seat for a waiting voice. None when a newer loop already holds it: that loop carries the newest press, so an older voice is the one to drop.

Source

async fn render_previews(&self, seat: &SessionSlot) -> Result<(), SayError>

Drain the seat’s pending previews, newest last.

Source

fn listening_queue( &self, seat: &SessionSlot, ) -> Result<UnboundedSender<Job>, SayError>

The queue of a seat that still has a listener. A say reads it again after a load, because the seat can empty while the engine loads.

Source

pub fn set_listening( &self, seat: &SessionSlot, client: u64, on: bool, explicit: bool, )

Turn one client’s voice on or off for seat. The session is told on the first client in, and on the last client out only when the reader turned it off themselves: a move to another seat pauses the seat without toggling the agent.

Source

pub async fn replace_engine(&self, engine: Arc<dyn Engine>)

Swap the loaded engine for one already built, so a model change keeps serving until the new engine is up.

Source

pub fn listeners(&self, seat: &SessionSlot) -> usize

Source

pub fn release(&self, client: u64) -> Vec<SessionSlot>

A connection has gone: take it off every seat it was listening to, and answer the seats whose count changed. A socket that dies says no goodbye, so this teardown is what lowers the count.

Source

pub fn enabled(&self) -> bool

Whether [tts] enabled is set. A disabled service registers no tool and refuses every say.

Source

pub fn occupant_changed(&self, seat: &SessionSlot)

The seat’s occupant changed under a listening client: tell the new session it is heard, because the note fires on the listener set’s transitions and a /new or /resume leaves that set alone.

Source

pub(crate) async fn warm(&self) -> Result<(), SayError>

Load the engine ahead of the first say. A failed load leaves the slot empty, so the first say retries it.

Source

async fn engine(&self) -> Result<Arc<dyn Engine>, SayError>

The engine, loading it on the first caller. The mutex is held across the load, so a second say waits for it instead of racing it.

Source

fn spawn_queue( &self, seat: &SessionSlot, live: Arc<AtomicUsize>, ) -> UnboundedSender<Job>

The seat’s render loop. It stops the moment the last listener leaves, so a queued utterance is not rendered into a seat nobody hears.

Trait Implementations§

Source§

impl Clone for VoiceService

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more