pub struct TTSPlugin { /* private fields */ }Expand description
TTS Plugin implementing AgentPlugin
Implementations§
Source§impl TTSPlugin
impl TTSPlugin
Sourcepub fn with_engine<E: TTSEngine + 'static>(
plugin_id: &str,
engine: E,
default_voice: Option<&str>,
) -> Self
pub fn with_engine<E: TTSEngine + 'static>( plugin_id: &str, engine: E, default_voice: Option<&str>, ) -> Self
Create a TTS plugin with engine and voice (便捷方法)
§参数
plugin_id: 插件IDengine: 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"));Sourcepub fn with_config(self, config: TTSPluginConfig) -> Self
pub fn with_config(self, config: TTSPluginConfig) -> Self
Set the plugin configuration
Sourcepub fn with_engine_ref<E: TTSEngine + 'static>(self, engine: E) -> Self
pub fn with_engine_ref<E: TTSEngine + 'static>(self, engine: E) -> Self
Set a custom TTS engine (链式调用版本,用于已有实例)
Sourcepub fn with_voice(self, voice: &str) -> Self
pub fn with_voice(self, voice: &str) -> Self
Set the default voice
Sourcepub async fn synthesize_and_play(&mut self, text: &str) -> PluginResult<()>
pub async fn synthesize_and_play(&mut self, text: &str) -> PluginResult<()>
Synthesize text to audio and play it
Sourcepub async fn synthesize_to_audio(&mut self, text: &str) -> PluginResult<Vec<u8>>
pub async fn synthesize_to_audio(&mut self, text: &str) -> PluginResult<Vec<u8>>
Synthesize text to audio data (no playback)
Sourcepub async fn synthesize_streaming(
&mut self,
text: &str,
callback: Box<dyn Fn(Vec<u8>) + Send + Sync>,
) -> PluginResult<()>
pub async fn synthesize_streaming( &mut self, text: &str, callback: Box<dyn Fn(Vec<u8>) + Send + Sync>, ) -> PluginResult<()>
Stream synthesize text with callback
Sourcepub async fn synthesize_streaming_f32(
&mut self,
text: &str,
callback: Box<dyn Fn(Vec<f32>) + Send + Sync>,
) -> PluginResult<()>
pub async fn synthesize_streaming_f32( &mut self, text: &str, callback: Box<dyn Fn(Vec<f32>) + Send + Sync>, ) -> PluginResult<()>
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 synthesizecallback: 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?;Sourcepub async fn list_voices(&self) -> PluginResult<Vec<VoiceInfo>>
pub async fn list_voices(&self) -> PluginResult<Vec<VoiceInfo>>
List available voices
Sourcepub fn set_default_voice(&mut self, voice: &str)
pub fn set_default_voice(&mut self, voice: &str)
Set the default voice
Sourcepub fn last_audio(&self) -> Vec<u8> ⓘ
pub fn last_audio(&self) -> Vec<u8> ⓘ
Get the last synthesized audio data
Trait Implementations§
Source§impl AgentPlugin for TTSPlugin
impl AgentPlugin for TTSPlugin
Source§fn metadata(&self) -> &PluginMetadata
fn metadata(&self) -> &PluginMetadata
获取插件元数据
Source§fn state(&self) -> PluginState
fn state(&self) -> PluginState
获取插件状态
Source§fn load<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ctx: &'life1 PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ctx: &'life1 PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
插件加载(分配资源)
Source§fn init_plugin<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = PluginResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn init_plugin<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = PluginResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
插件初始化(配置初始化)
Source§fn start<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = PluginResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn start<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = PluginResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
插件启动
Source§fn stop<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = PluginResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stop<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = PluginResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
插件停止
Source§fn unload<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = PluginResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn unload<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = PluginResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
插件卸载(释放资源)
Source§fn execute<'life0, 'async_trait>(
&'life0 mut self,
input: String,
) -> Pin<Box<dyn Future<Output = PluginResult<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 mut self,
input: String,
) -> Pin<Box<dyn Future<Output = PluginResult<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
执行插件功能
Source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
转换为可变 Any
Source§fn plugin_type(&self) -> PluginType
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,
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,
插件暂停
Auto Trait Implementations§
impl Freeze for TTSPlugin
impl !RefUnwindSafe for TTSPlugin
impl Send for TTSPlugin
impl Sync for TTSPlugin
impl Unpin for TTSPlugin
impl UnsafeUnpin for TTSPlugin
impl !UnwindSafe for TTSPlugin
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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