1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! novel-tts 是一个专门为小说阅读设计的文本转语音(TTS)库。
//! 它基于 [kokoro-tts](https://github.com/mzdk100/kokoro) 引擎,
//! 提供了针对长文本(如小说章节)优化的流式处理功能。
//!
//! ## 功能特性
//!
//! - 📚 专为小说阅读优化的TTS解决方案
//! - 🌊 流式音频处理,支持边生成边播放
//! - 🎵 支持多种语音选择
//! - 🔁 实时字符位置追踪,便于同步文本高亮
//! - ⏹️ 支持播放控制(暂停、取消)
//! - 📦 自动下载和管理TTS模型文件
//! - 🧵 异步API设计,适用于现代Rust应用
//!
//! ## 快速开始
//!
//! ```rust
//! use novel_tts::{NovelTTS, CheckpointModel, VoicesData, ChapterTTS};
//! use kokoro_tts::Voice;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! // 初始化模型和语音数据
//! let model = CheckpointModel::default();
//! let voices = VoicesData::default();
//!
//! // 检查并下载必要的模型文件
//! if !model.is_downloaded() {
//! model.async_download(|downloaded, total| {
//! println!("模型下载进度: {}/{}", downloaded, total);
//! }).await?;
//! }
//!
//! if !voices.is_downloaded() {
//! voices.async_download(|downloaded, total| {
//! println!("语音数据下载进度: {}/{}", downloaded, total);
//! }).await?;
//! }
//!
//! // 创建TTS实例
//! let novel_tts = NovelTTS::new(&model, &voices).await?;
//! let mut chapter_tts = novel_tts.chapter_tts();
//!
//! // 准备要转换的文本
//! let text = "这是小说的第一段落。\n这是第二段落。".to_string();
//!
//! // 流式处理文本到音频
//! let (audio_queue, mut position_rx) = chapter_tts.stream(
//! text,
//! Voice::Zf006(1),
//! |error| eprintln!("TTS处理错误: {:?}", error)
//! )?;
//!
//! // 监听字符位置更新
//! tokio::spawn(async move {
//! while let Some((start, end)) = position_rx.recv().await {
//! println!("正在朗读字符位置: {} 到 {}", start, end);
//! }
//! });
//! # Ok(())
//! # }
//! ```
// 重新导出公共类型
pub use *;
pub use *;
pub use kokoro_tts;
use KokoroTts;
pub use *;
pub use *;
use ;
use Arc;
/// NovelTTS主结构体
///
/// 负责管理TTS引擎实例,是整个TTS功能的核心入口点。
unsafe
unsafe