Skip to main content

TTSPlugin

Struct TTSPlugin 

Source
pub struct TTSPlugin { /* private fields */ }
Expand description

TTS Plugin implementing AgentPlugin

Implementations§

Source§

impl TTSPlugin

Source

pub fn new(plugin_id: &str) -> TTSPlugin

Create a new TTS plugin

Source

pub fn with_engine<E>( plugin_id: &str, engine: E, default_voice: Option<&str>, ) -> TTSPlugin
where E: TTSEngine + 'static,

Create a TTS plugin with engine and voice (便捷方法)

§参数
  • plugin_id: 插件ID
  • engine: TTS 引擎
  • default_voice: 默认音色,如 "zf_090",默认为 "default"
§示例
use mofa_plugins::TTSPlugin;

// 使用默认音色
let plugin = TTSPlugin::with_engine("tts", kokoro_engine, None);

// 指定音色
let plugin = TTSPlugin::with_engine("tts", kokoro_engine, Some("zf_090"));
Source

pub fn with_config(self, config: TTSPluginConfig) -> TTSPlugin

Set the plugin configuration

Source

pub fn with_engine_ref<E>(self, engine: E) -> TTSPlugin
where E: TTSEngine + 'static,

Set a custom TTS engine (链式调用版本,用于已有实例)

Source

pub fn with_voice(self, voice: &str) -> TTSPlugin

Set the default voice

Source

pub fn engine(&self) -> Option<&Arc<dyn TTSEngine>>

Get the TTS engine

Source

pub async fn synthesize_and_play(&mut self, text: &str) -> Result<(), Error>

Synthesize text to audio and play it

Source

pub async fn synthesize_to_audio( &mut self, text: &str, ) -> Result<Vec<u8>, Error>

Synthesize text to audio data (no playback)

Source

pub async fn synthesize_streaming( &mut self, text: &str, callback: Box<dyn Fn(Vec<u8>) + Sync + Send>, ) -> Result<(), Error>

Stream synthesize text with callback

Source

pub async fn synthesize_streaming_f32( &mut self, text: &str, callback: Box<dyn Fn(Vec<f32>) + Sync + Send>, ) -> Result<(), Error>

Stream synthesize text with f32 callback (native format)

This method is more efficient for KokoroTTS as it uses the native f32 format without the overhead of f32 -> i16 -> u8 conversion.

§Arguments
  • text: The text to synthesize
  • callback: Function to call with each audio chunk (Vec)
§Example
plugin.synthesize_streaming_f32("Hello", Box::new(|audio_f32| {
    // audio_f32 is Vec<f32> with values in [-1.0, 1.0]
    sink.append(SamplesBuffer::new(1, 24000, audio_f32));
})).await?;
Source

pub async fn list_voices(&self) -> Result<Vec<VoiceInfo>, Error>

List available voices

Source

pub fn set_default_voice(&mut self, voice: &str)

Set the default voice

Source

pub fn stats(&self) -> HashMap<String, Value>

Get synthesis statistics

Source

pub fn last_audio(&self) -> Vec<u8>

Get the last synthesized audio data

Trait Implementations§

Source§

impl AgentPlugin for TTSPlugin

Source§

fn metadata(&self) -> &PluginMetadata

获取插件元数据
Source§

fn state(&self) -> PluginState

获取插件状态
Source§

fn load<'life0, 'life1, 'async_trait>( &'life0 mut self, ctx: &'life1 PluginContext, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, TTSPlugin: 'async_trait,

插件加载(分配资源)
Source§

fn init_plugin<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, TTSPlugin: 'async_trait,

插件初始化(配置初始化)
Source§

fn start<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, TTSPlugin: 'async_trait,

插件启动
Source§

fn stop<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, TTSPlugin: 'async_trait,

插件停止
Source§

fn unload<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, TTSPlugin: 'async_trait,

插件卸载(释放资源)
Source§

fn execute<'life0, 'async_trait>( &'life0 mut self, input: String, ) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, TTSPlugin: 'async_trait,

执行插件功能
Source§

fn stats(&self) -> HashMap<String, Value>

获取插件统计信息
Source§

fn as_any(&self) -> &(dyn Any + 'static)

转换为 Any(用于向下转型)
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

转换为可变 Any
Source§

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

消费并转换为 Any(用于提取具体的插件类型)
Source§

fn plugin_id(&self) -> &str

获取插件 ID(便捷方法)
Source§

fn plugin_type(&self) -> PluginType

获取插件类型
Source§

fn pause<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

插件暂停
Source§

fn resume<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

插件恢复
Source§

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

健康检查

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
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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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
Source§

impl<T> Message for T
where T: Any + Send + 'static,

Source§

fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>

Convert a BoxedMessage to this concrete type
Source§

fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>

Convert this message to a BoxedMessage
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> State for T
where T: Any + Send + 'static,