| Crates.io | voirs-emotion |
| lib.rs | voirs-emotion |
| version | 0.1.0-alpha.1 |
| created_at | 2025-09-21 04:12:42.991962+00 |
| updated_at | 2025-09-21 04:12:42.991962+00 |
| description | Emotion expression control system for VoiRS voice synthesis |
| homepage | https://github.com/cool-japan/voirs |
| repository | https://github.com/cool-japan/voirs |
| max_upload_size | |
| id | 1848422 |
| size | 1,476,538 |
Emotion Expression Control System for Neural Speech Synthesis
This crate provides comprehensive emotion expression control for voice synthesis, enabling dynamic emotional expression through prosody modification, acoustic parameter adjustment, and emotion interpolation.
use voirs_emotion::prelude::*;
#[tokio::main]
async fn main() -> Result<()> {
// Create emotion processor with default configuration
let processor = EmotionProcessor::builder()
.with_default_config()
.build()?;
// Create emotion state
let emotion = EmotionState::new(
Emotion::Happy,
EmotionIntensity::Medium,
);
// Apply emotion to prosody parameters
let prosody_params = ProsodyParameters::default();
let emotional_prosody = processor
.apply_emotion(&prosody_params, &emotion)
.await?;
println!("Emotional prosody: {:?}", emotional_prosody);
Ok(())
}
use voirs_emotion::prelude::*;
// Create two emotion states
let happy = EmotionState::new(Emotion::Happy, EmotionIntensity::High);
let calm = EmotionState::new(Emotion::Calm, EmotionIntensity::Low);
// Create interpolator
let interpolator = EmotionInterpolator::new(InterpolationMethod::Linear);
// Interpolate between emotions (0.0 = happy, 1.0 = calm)
let blended_emotion = interpolator.interpolate(&happy, &calm, 0.3)?;
use voirs_emotion::prelude::*;
// Create custom emotion configuration
let config = EmotionConfig::builder()
.with_pitch_range(0.8, 1.4) // 80% to 140% of base pitch
.with_speed_range(0.7, 1.2) // 70% to 120% of base speed
.with_energy_range(0.6, 1.5) // 60% to 150% of base energy
.with_emotion_sensitivity(0.8)
.build()?;
let processor = EmotionProcessor::builder()
.with_config(config)
.build()?;
use voirs_emotion::types::*;
// Create emotion with specific parameters
let emotion_params = EmotionParameters {
arousal: 0.8, // High energy
valence: 0.7, // Positive emotion
dominance: 0.6, // Moderate confidence
intensity: EmotionIntensity::High,
};
let custom_emotion = EmotionState::from_parameters(emotion_params);
use voirs_emotion::prosody::*;
// Configure prosody modifier
let modifier = ProsodyModifier::builder()
.with_pitch_scale(1.2) // 20% pitch increase
.with_tempo_scale(0.9) // 10% slower
.with_energy_scale(1.1) // 10% louder
.with_stress_emphasis(1.3) // 30% more stress
.build()?;
use voirs_emotion::prelude::*;
use tokio::time::{interval, Duration};
#[tokio::main]
async fn main() -> Result<()> {
let processor = EmotionProcessor::builder()
.with_real_time_config()
.build()?;
let mut timer = interval(Duration::from_millis(100));
let mut current_emotion = EmotionState::neutral();
loop {
timer.tick().await;
// Update emotion based on external input
let new_emotion = get_emotion_from_input().await?;
// Smooth transition between emotions
current_emotion = processor
.transition_emotion(¤t_emotion, &new_emotion, 0.1)
.await?;
// Apply to synthesis pipeline
apply_emotion_to_synthesis(¤t_emotion).await?;
}
}
use voirs_emotion::ssml::*;
// Parse SSML with emotion markup
let ssml_text = r#"
<speak>
<emotion name="happy" intensity="medium">
Hello there!
</emotion>
<emotion name="calm" intensity="low">
How are you doing today?
</emotion>
</speak>
"#;
let emotion_elements = EmotionSSMLParser::parse(ssml_text)?;
for element in emotion_elements {
let emotion_state = EmotionState::from_ssml(&element)?;
// Process with emotion
}
# Run emotion processing tests
cargo test --package voirs-emotion
# Run emotion interpolation tests
cargo test --package voirs-emotion interpolation
# Run SSML parsing tests
cargo test --package voirs-emotion ssml
# Run performance benchmarks
cargo bench --package voirs-emotion
use voirs_emotion::acoustic::*;
// Enable acoustic integration feature
let emotion_conditioner = AcousticEmotionConditioner::new();
let conditioned_features = emotion_conditioner
.condition_features(&acoustic_features, &emotion_state)
.await?;
| Operation | Time | Memory | Notes |
|---|---|---|---|
| Emotion Processing | 2.3ms | 12MB | Single emotion state |
| Interpolation | 1.1ms | 8MB | Linear interpolation |
| SSML Parsing | 5.7ms | 20MB | Complex markup |
| Real-time Stream | 0.8ms | 15MB | Per 100ms chunk |
See the examples/ directory for comprehensive usage examples:
emotion_control_example.rs - Basic emotion controlemotion_interpolation.rs - Emotion blendingrealtime_emotion.rs - Real-time processingLicensed under either of Apache License 2.0 or MIT License at your option.
Part of the VoiRS neural speech synthesis ecosystem.