1pub mod properties_util;
8pub mod ref_audio_utilities;
9pub mod rwkv_sampler;
10pub mod tts_state_manager;
11pub mod tts_pipeline_fixes;
13
14pub mod global_sampler_manager;
16pub mod onnx_session_pool;
17pub mod dynamic_batch_manager;
19pub mod lightweight_tts_pipeline;
20pub mod voice_feature;
21pub mod voice_feature_manager;
22
23pub mod batch_types;
25pub mod feature_extractor;
26pub mod sampler_manager;
27pub mod shared_runtime;
28
29pub mod normal_mode_inference;
31pub mod zero_shot_inference;
32
33pub mod inference_state_manager;
35pub mod streaming_inference;
36
37pub use tts_state_manager::{
39 TtsInferContext, TtsInferOptions, TtsStateId, TtsStateManager, TtsStateStats,
40};
41
42pub use properties_util::*;
45pub use ref_audio_utilities::RefAudioUtilities;
46pub use rwkv_sampler::{RwkvSampler, SamplerArgs, TtsBatchRequest};
47pub mod tts_generator {
51 use crate::{RefAudioUtilities, RwkvSampler};
54
55 use anyhow::Result;
56
57 #[derive(Debug)]
59 pub struct Args {
60 pub text: String,
61 pub model_path: String,
62 pub vocab_path: String,
63 pub output_path: String,
64 pub temperature: f32,
65 pub top_p: f32,
66 pub top_k: usize,
67 pub max_tokens: usize,
68 pub age: String,
69 pub gender: String,
70 pub emotion: String,
71 pub pitch: String,
72 pub speed: String,
73 pub validate: bool,
74 pub zero_shot: bool,
75 pub ref_audio_path: String,
76 pub prompt_text: String,
77 }
78
79 pub struct TTSGenerator {
81 pub rwkv_sampler: Option<RwkvSampler>,
83 pub ref_audio_utilities: Option<RefAudioUtilities>,
85 }
86
87 impl TTSGenerator {
88 pub fn new() -> Self {
90 Self {
91 rwkv_sampler: None,
92 ref_audio_utilities: None,
93 }
94 }
95
96 pub async fn new_async(model_path: String, vocab_path: String) -> Result<Self> {
98 let quant_config = None;
100 let rwkv_sampler =
101 RwkvSampler::new(&model_path, &vocab_path, quant_config, 256).await?;
102
103 Ok(Self {
104 rwkv_sampler: Some(rwkv_sampler),
105 ref_audio_utilities: None,
106 })
107 }
108
109 pub fn with_rwkv_sampler(mut self, sampler: RwkvSampler) -> Self {
111 self.rwkv_sampler = Some(sampler);
112 self
113 }
114
115 pub fn with_ref_audio_utilities(mut self, utilities: RefAudioUtilities) -> Self {
117 self.ref_audio_utilities = Some(utilities);
118 self
119 }
120
121 pub async fn generate(&self, _text: &str, _args: &Args) -> Result<Vec<f32>> {
123 Err(anyhow::anyhow!(
124 "TtsPipeline已移动到备份目录,请使用lightweight_tts_pipeline"
125 ))
126 }
127
128 pub fn save_audio(
130 &self,
131 audio_samples: &[f32],
132 output_path: &str,
133 sample_rate: u32,
134 ) -> Result<()> {
135 let spec = hound::WavSpec {
140 channels: 1,
141 sample_rate,
142 bits_per_sample: 32,
143 sample_format: hound::SampleFormat::Float,
144 };
145
146 let mut writer = hound::WavWriter::create(output_path, spec)?;
147 for &sample in audio_samples {
148 writer.write_sample(sample)?;
149 }
150 writer.finalize()?;
151
152 Ok(())
153 }
154 }
155
156 impl Default for TTSGenerator {
157 fn default() -> Self {
158 Self::new()
159 }
160 }
161}
162
163#[cfg(test)]
165mod tests {
166 #[test]
167 fn test_basic_functionality() {
168 assert_eq!(2 + 2, 4);
170 }
171}