speechflow 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. speechflow-0.1.0/.gitignore +87 -0
  2. speechflow-0.1.0/CLAUDE.md +329 -0
  3. speechflow-0.1.0/LICENSE +21 -0
  4. speechflow-0.1.0/PKG-INFO +236 -0
  5. speechflow-0.1.0/README.md +199 -0
  6. speechflow-0.1.0/pyproject.toml +82 -0
  7. speechflow-0.1.0/scripts/fishaudio_demo.py +183 -0
  8. speechflow-0.1.0/scripts/gemini_demo.py +150 -0
  9. speechflow-0.1.0/scripts/kokoro_demo.py +173 -0
  10. speechflow-0.1.0/scripts/openai_demo.py +156 -0
  11. speechflow-0.1.0/scripts/stylebert_demo.py +171 -0
  12. speechflow-0.1.0/src/speechflow/__init__.py +24 -0
  13. speechflow-0.1.0/src/speechflow/audio/__init__.py +7 -0
  14. speechflow-0.1.0/src/speechflow/audio/player.py +211 -0
  15. speechflow-0.1.0/src/speechflow/audio/writer.py +162 -0
  16. speechflow-0.1.0/src/speechflow/core/__init__.py +10 -0
  17. speechflow-0.1.0/src/speechflow/core/base.py +69 -0
  18. speechflow-0.1.0/src/speechflow/core/exceptions.py +23 -0
  19. speechflow-0.1.0/src/speechflow/engines/__init__.py +7 -0
  20. speechflow-0.1.0/src/speechflow/engines/fishaudio.py +189 -0
  21. speechflow-0.1.0/src/speechflow/engines/fishspeech.py +72 -0
  22. speechflow-0.1.0/src/speechflow/engines/gemini.py +284 -0
  23. speechflow-0.1.0/src/speechflow/engines/kokoro.py +272 -0
  24. speechflow-0.1.0/src/speechflow/engines/openai.py +152 -0
  25. speechflow-0.1.0/src/speechflow/engines/stylebert.py +336 -0
  26. speechflow-0.1.0/tests/README.md +59 -0
  27. speechflow-0.1.0/tests/__init__.py +1 -0
  28. speechflow-0.1.0/tests/conftest.py +49 -0
  29. speechflow-0.1.0/tests/integration/__init__.py +1 -0
  30. speechflow-0.1.0/tests/integration/test_gemini_integration.py +53 -0
  31. speechflow-0.1.0/tests/unit/__init__.py +1 -0
  32. speechflow-0.1.0/tests/unit/test_audio_data.py +54 -0
  33. speechflow-0.1.0/tests/unit/test_exceptions.py +67 -0
  34. speechflow-0.1.0/tests/unit/test_gemini_engine.py +124 -0
  35. speechflow-0.1.0/tests/unit/test_kokoro_engine.py +313 -0
  36. speechflow-0.1.0/tests/unit/test_openai_engine.py +229 -0
  37. speechflow-0.1.0/tests/unit/test_stylebert_engine.py +280 -0
  38. speechflow-0.1.0/tests/unit/test_tts_engine_base.py +148 -0
@@ -0,0 +1,87 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ env/
8
+ venv/
9
+ ENV/
10
+ .venv
11
+ *.egg-info/
12
+ dist/
13
+ build/
14
+ *.egg
15
+ .eggs/
16
+ .pytest_cache/
17
+ .coverage
18
+ .tox/
19
+ .mypy_cache/
20
+ .dmypy.json
21
+ dmypy.json
22
+ .pyre/
23
+ .ruff_cache/
24
+ *.pyc
25
+
26
+ # Virtual environments
27
+ .venv/
28
+ venv/
29
+ ENV/
30
+ env/
31
+
32
+ # IDE
33
+ .vscode/
34
+ .idea/
35
+ *.swp
36
+ *.swo
37
+ *~
38
+ .DS_Store
39
+
40
+ # Project specific
41
+ sandbox/
42
+ .env
43
+ *.wav
44
+ *.mp3
45
+ *.flac
46
+ *.ogg
47
+ *.m4a
48
+ *.aac
49
+
50
+ # Dependencies
51
+ uv.lock
52
+ .python-version
53
+
54
+ # Testing
55
+ htmlcov/
56
+ .coverage
57
+ coverage.xml
58
+ *.cover
59
+ .hypothesis/
60
+
61
+ # Logs
62
+ *.log
63
+ logs/
64
+
65
+ # Temporary files
66
+ *.tmp
67
+ *.temp
68
+ tmp/
69
+ temp/
70
+
71
+ # PyTorch
72
+ *.pth
73
+ *.pt
74
+ checkpoints/
75
+ models/
76
+
77
+ # Jupyter
78
+ .ipynb_checkpoints/
79
+ *.ipynb
80
+
81
+ # OS
82
+ Thumbs.db
83
+ .DS_Store
84
+
85
+ # Claude
86
+ .claude/
87
+ output/
@@ -0,0 +1,329 @@
1
+ # SpeechFlow プロジェクト要件定義書
2
+
3
+ ## プロジェクト概要
4
+ **SpeechFlow**は、複数のTTSエンジンを統一的なインターフェースで扱えるPython用音声合成ラッパーライブラリです。
5
+
6
+ ### 目的
7
+ - 他アプリケーションのバックエンドとして利用可能な音声合成ライブラリの提供
8
+ - TTSエンジンの差し替えを容易にする抽象化層の実装
9
+ - シンプルで使いやすいPythonic APIの提供
10
+
11
+ ## 技術要件
12
+
13
+ ### 対応環境
14
+ - Python 3.12以上
15
+ - クロスプラットフォーム対応(Windows、macOS、Linux)
16
+ - CUDA対応(PyTorch使用時)
17
+
18
+ ### 対応TTSエンジン
19
+ 1. **OpenAI TTS** - OpenAI APIを使用したテキスト音声合成
20
+ 2. **Google GenAI** - Google GenAI APIを使用したTTS(google-genai使用)
21
+ 3. **FishAudio** - FishAudio APIを使用したクラウドベースTTS
22
+ 4. **Kokoro** - Kokoroライブラリを使用したTTS
23
+ 5. **Style-Bert-VITS2** - ローカルで動作する高品質なTTSモデル
24
+
25
+ ### 主要機能
26
+ 1. **テキストプロンプト入力**
27
+ - 統一的なテキスト入力インターフェース
28
+ - 各TTSエンジン固有のオプションを抽象化
29
+
30
+ 2. **ストリーミング機能**
31
+ - リアルタイム音声ストリーミング対応
32
+ - バッファリング制御
33
+
34
+ 3. **音声ファイル保存**
35
+ - WAV、MP3等の一般的な音声形式での保存
36
+ - メタデータの付与
37
+
38
+ 4. **PyAudio統合**
39
+ - 直接音声再生機能
40
+ - 再生制御(再生、停止、一時停止)
41
+
42
+ ## アーキテクチャ設計
43
+
44
+ ### クラス構造
45
+ ```
46
+ speechflow/
47
+ ├── __init__.py
48
+ ├── core/
49
+ │ ├── __init__.py
50
+ │ ├── base.py # 抽象基底クラス
51
+ │ └── exceptions.py # カスタム例外
52
+ ├── engines/
53
+ │ ├── __init__.py
54
+ │ ├── openai.py # OpenAI TTS実装
55
+ │ ├── gemini.py # Google GenAI TTS実装
56
+ │ ├── fish_audio.py # FishAudio TTS実装
57
+ │ ├── fishspeech.py # FishSpeech TTS実装(スケルトン)
58
+ │ ├── kokoro.py # Kokoro TTS実装
59
+ │ └── stylebert.py # Style-Bert-VITS2実装
60
+ ├── audio/
61
+ │ ├── __init__.py
62
+ │ ├── player.py # PyAudio再生機能
63
+ │ └── writer.py # ファイル保存機能
64
+ └── utils/
65
+ ├── __init__.py
66
+ └── audio_processing.py # NumPy音声処理
67
+ ```
68
+
69
+ ### 主要インターフェース
70
+ ```python
71
+ from speechflow import OpenAITTSEngine, AudioPlayer, AudioWriter
72
+
73
+ # コンポーネントの初期化(分離されたアーキテクチャ)
74
+ engine = OpenAITTSEngine(api_key="your-api-key")
75
+ player = AudioPlayer()
76
+ writer = AudioWriter()
77
+
78
+ # 基本的な音声合成
79
+ audio = engine.get("こんにちは、世界!")
80
+
81
+ # 音声再生
82
+ player.play(audio)
83
+
84
+ # ファイル保存
85
+ writer.save(audio, "output.wav")
86
+
87
+ # ストリーミング再生(結合されたAudioDataを返す)
88
+ combined_audio = player.play_stream(engine.stream("長いテキストをストリーミング..."))
89
+
90
+ # ストリーミング保存(結合されたAudioDataを返す)
91
+ combined_audio = writer.save_stream(engine.stream("テキスト"), "output.wav")
92
+ ```
93
+
94
+ ### 設定管理
95
+ 現在、各TTSエンジンは独立して初期化され、APIキーは初期化時に直接渡されます。
96
+ 環境変数や.envファイルからの読み込みは、アプリケーション側で実装してください。
97
+
98
+ ```python
99
+ # 例:アプリケーション側での設定管理
100
+ import os
101
+ from speechflow import OpenAITTSEngine
102
+
103
+ # 環境変数から読み込み
104
+ engine = OpenAITTSEngine(api_key=os.getenv("OPENAI_API_KEY"))
105
+
106
+ # または直接指定
107
+ engine = OpenAITTSEngine(api_key="your-api-key")
108
+ ```
109
+
110
+ ## 実装状況(2025年1月時点)
111
+
112
+ ### 完了済み
113
+ 1. **コア機能**
114
+ - TTSエンジンの抽象化インターフェース(TTSEngineBase)
115
+ - 統一API(get/stream メソッド)
116
+ - AudioDataクラスによる音声データ管理
117
+
118
+ 2. **エンジン実装**
119
+ - OpenAI TTS(PCMフォーマット、真のストリーミング対応)
120
+ - Gemini TTS(単一チャンクストリーミング、speed パラメータ対応)
121
+ - FishAudio TTS(ストリーミング対応)
122
+ - Kokoro TTS(多言語対応、ローカル実行)
123
+ - Style-Bert-VITS2(日本語特化、感情表現対応)
124
+
125
+ 3. **音声処理機能**
126
+ - AudioPlayer(同期的再生、ストリーミング対応)
127
+ - AudioWriter(ファイル保存、ストリーミング保存)
128
+ - 分離されたアーキテクチャ(エンジン/プレイヤー/ライター独立)
129
+
130
+ ### 未実装
131
+ 1. **エンジン**
132
+ - FishSpeech TTS(スケルトンのみ)
133
+
134
+ 2. **追加機能**
135
+ - 非同期処理(asyncio対応)
136
+ - キャッシング機能
137
+ - 音声パラメータの統一的な制御
138
+ - 統一的な設定管理システム
139
+
140
+ ## 依存関係
141
+
142
+ ### コア依存関係(pyproject.tomlに定義済み)
143
+ - `numpy>=1.26.4` - 音声データ処理
144
+ - `pyaudio>=0.2.14` - 音声再生
145
+ - `pydantic>=2.0` - データ検証
146
+
147
+ ### TTSエンジン依存関係
148
+ - `openai>=1.84.0` - OpenAI TTS
149
+ - `google-genai>=1.18.0` - Google GenAI TTS
150
+ - `fish-audio-sdk>=2025.6.3` - FishAudio TTS
151
+ - `kokoro>=0.9.4` - Kokoro TTS
152
+ - `style-bert-vits2>=2.5.0` - Style-Bert-VITS2
153
+ - `pyopenjtalk>=0.4.1` - 日本語音声処理(Style-Bert-VITS2用)
154
+ - `misaki[ja]>=0.9.4` - 日本語辞書(Kokoro日本語用)
155
+
156
+ ### PyTorch依存関係(CUDA対応)
157
+ - `torch` - Style-Bert-VITS2で使用
158
+ - `torchvision` - 画像処理(何かのライブラリが使うかもしれないという念のためのimport)
159
+ - `torchaudio` - 音声処理(何かのライブラリが使うかもしれないという念のためのimport)
160
+ - CUDA 12.6対応のPyTorchインデックスを使用
161
+
162
+ ## 実装上の重要な注意事項
163
+
164
+ ### ストリーミング仕様(2025年8月時点)
165
+
166
+ #### OpenAI TTS
167
+ - **真のストリーミング対応**: 複数の小さなチャンクを順次返す
168
+ - **コールドスタート問題**: 最初のAPI呼び出しは10-20秒の遅延が発生
169
+ - **Warmup推奨**: 初期化時にwarmup呼び出しを行うことで、以降の低レイテンシを実現
170
+ - **使用フォーマット**: PCM(シンプルな実装のため)
171
+
172
+ #### Gemini TTS
173
+ - **単一チャンク仕様**: ドキュメント上はストリーミング対応だが、実際は全音声を1チャンクで返す
174
+ - **既知の制限**: Google AI Developers Forumで確認済みの仕様
175
+ - **遅延**: 全音声生成完了まで待機(6-57秒、テキスト長に依存)
176
+ - **speed パラメータ**: 音声速度調整対応(API一貫性のため追加)
177
+
178
+ #### FishAudio TTS
179
+ - **真のストリーミング対応**: リアルタイムでチャンクを返す
180
+ - **モデル選択**: s1, s1-mini, speech-1.6, speech-1.5, agent-x0
181
+ - **カスタムボイス**: ユーザー定義のボイスIDを使用可能
182
+
183
+ #### Kokoro TTS
184
+ - **ローカル実行**: GPU/CPU上で動作
185
+ - **多言語対応**: 9言語(英語、スペイン語、フランス語、日本語など)
186
+ - **ストリーミング**: 文単位での生成(真のストリーミングではない)
187
+
188
+ #### Style-Bert-VITS2
189
+ - **日本語特化**: 日本語テキストに最適化
190
+ - **感情表現**: 7つの感情スタイル対応
191
+ - **ストリーミング**: 文単位での生成(真のストリーミングではない)
192
+ - **GPU推奨**: 高速な音声生成にはGPUが必要
193
+
194
+ ## 今後の検討事項
195
+ - 音声パラメータ(速度、ピッチ、音量)の統一的な制御
196
+ - キャッシング機能
197
+ - 非同期処理のサポート(asyncio対応)
198
+ - より多くのTTSエンジンへの対応
199
+ - 音声品質評価メトリクスの実装
200
+ - マルチ言語対応の強化
201
+
202
+ ## 参考資料
203
+ ### Gemini TTS
204
+ https://zenn.dev/sonicmoov/articles/bd862039bcba46
205
+
206
+ ### OpenAI
207
+ https://qiita.com/syukan3/items/59212050a470408ecc2b
208
+
209
+ ### Kokoro
210
+ https://qiita.com/syun88/items/1c33c967e06c57fb938f
211
+
212
+ ## Style-Bert-VITS2
213
+ https://zenn.dev/asap/articles/f8c0621cdd74cc
214
+ https://note.com/sirodon_256/n/n40b2b1bd5aca
215
+
216
+ ## FishAudio
217
+ https://docs.fish.audio/text-to-speech/text-to-speech
218
+ https://docs.fish.audio/text-to-speech/fine-grained-control
219
+ https://docs.fish.audio/emotion-control/tts-emotion-and-control-tags-user-guide
220
+
221
+ ## 実装ガイドライン
222
+
223
+ ### コード規約
224
+ - すべてのTTSエンジンクラスは `TTSEngine` サフィックスを使用
225
+ - 統一API: `get()` メソッド(同期的な音声合成)、`stream()` メソッド(ストリーミング)
226
+ - `synthesize()` メソッドは廃止(`get()` を使用)
227
+ - ファイル名はsnake_case(例: `fish_audio.py`、`fishspeech.py` ではなく `fish_speech.py` が望ましいが現状維持)
228
+
229
+ ## PyPIパッケージング・公開ガイド
230
+
231
+ ### 前提条件
232
+ - uvがインストールされていること
233
+ - PyPIアカウントを作成済みであること
234
+ - PyPI APIトークンを取得済みであること(推奨)
235
+
236
+ ### 1. パッケージのビルド
237
+
238
+ ```bash
239
+ # uvを使ってビルドツールを実行
240
+ uv run python -m build
241
+ ```
242
+
243
+ これにより、`dist/` ディレクトリに以下のファイルが生成されます:
244
+ - `speechflow-0.1.0.tar.gz` - ソース配布物
245
+ - `speechflow-0.1.0-py3-none-any.whl` - Wheel配布物
246
+
247
+ ### 2. ビルド結果の確認
248
+
249
+ ```bash
250
+ # 生成されたファイルの確認
251
+ ls dist/
252
+
253
+ # パッケージの内容確認
254
+ uv run twine check dist/*
255
+ ```
256
+
257
+ ### 3. TestPyPIへのアップロード(推奨)
258
+
259
+ 本番環境にアップロードする前に、TestPyPIでテストすることを推奨します。
260
+
261
+ ```bash
262
+ # TestPyPIにアップロード
263
+ uv run twine upload --repository testpypi dist/*
264
+ ```
265
+
266
+ TestPyPIからのインストールテスト:
267
+ ```bash
268
+ # 新しい仮想環境でテスト
269
+ uv venv test-env
270
+ uv pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ speechflow
271
+ ```
272
+
273
+ ### 4. 本番PyPIへのアップロード
274
+
275
+ ```bash
276
+ # PyPIにアップロード
277
+ uv run twine upload dist/*
278
+ ```
279
+
280
+ ### 5. 認証設定(オプション)
281
+
282
+ 毎回認証情報を入力する代わりに、`.pypirc` ファイルを設定できます:
283
+
284
+ ```ini
285
+ # ~/.pypirc
286
+ [distutils]
287
+ index-servers =
288
+ pypi
289
+ testpypi
290
+
291
+ [pypi]
292
+ username = __token__
293
+ password = pypi-AgEIcHlwaS5vcmc... # あなたのAPIトークン
294
+
295
+ [testpypi]
296
+ username = __token__
297
+ password = pypi-AgEIcHlwaS5vcmc... # TestPyPI用のAPIトークン
298
+ ```
299
+
300
+ ### 6. バージョン更新時の手順
301
+
302
+ 1. `pyproject.toml` の `version` を更新
303
+ 2. 変更をコミット
304
+ 3. Gitタグを作成: `git tag v0.1.1`
305
+ 4. `dist/` ディレクトリをクリーン: `rm -rf dist/`
306
+ 5. 新しいバージョンをビルド: `uv run python -m build`
307
+ 6. PyPIにアップロード: `uv run twine upload dist/*`
308
+
309
+ ### トラブルシューティング
310
+
311
+ - **パッケージ名の重複**: PyPIで既に使用されている名前は使えません
312
+ - **認証エラー**: APIトークンが正しく設定されているか確認
313
+ - **メタデータエラー**: `pyproject.toml` の必須フィールドを確認
314
+ - name, version, description, authors, license など
315
+
316
+ ### 必要なメタデータの確認
317
+
318
+ PyPIに公開する前に、以下のメタデータが `pyproject.toml` に含まれていることを確認:
319
+
320
+ - [x] name
321
+ - [x] version
322
+ - [x] description
323
+ - [x] readme
324
+ - [x] authors
325
+ - [x] license
326
+ - [x] requires-python
327
+ - [ ] keywords(オプション)
328
+ - [ ] classifiers(オプション)
329
+ - [ ] homepage/repository(オプション)
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 minamik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,236 @@
1
+ Metadata-Version: 2.4
2
+ Name: speechflow
3
+ Version: 0.1.0
4
+ Summary: TTS (Text-to-Speech) wrapper library for Python
5
+ Author-email: minamik <mia@sync.dev>
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Keywords: fishaudio,gemini,kokoro,openai,speech-synthesis,style-bert-vits2,text-to-speech,tts
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Requires-Python: >=3.10
19
+ Requires-Dist: en-core-web-sm
20
+ Requires-Dist: fish-audio-sdk>=2025.6.3
21
+ Requires-Dist: google-genai>=1.18.0
22
+ Requires-Dist: kokoro>=0.9.4
23
+ Requires-Dist: misaki[ja]>=0.9.4
24
+ Requires-Dist: numba>=0.61
25
+ Requires-Dist: numpy>=1.26.4
26
+ Requires-Dist: openai>=1.84.0
27
+ Requires-Dist: pip>=25.2
28
+ Requires-Dist: pyaudio>=0.2.14
29
+ Requires-Dist: pydantic>=2.0
30
+ Requires-Dist: pyopenjtalk>=0.4.1
31
+ Requires-Dist: python-dotenv>=1.1.1
32
+ Requires-Dist: style-bert-vits2>=2.5.0
33
+ Requires-Dist: torch
34
+ Requires-Dist: torchaudio
35
+ Requires-Dist: torchvision
36
+ Description-Content-Type: text/markdown
37
+
38
+ # SpeechFlow
39
+
40
+ A unified Python TTS (Text-to-Speech) library that provides a simple interface for multiple TTS engines.
41
+
42
+ ## Features
43
+
44
+ - **Multiple TTS Engine Support**:
45
+ - OpenAI TTS
46
+ - Google Gemini TTS
47
+ - FishAudio TTS (Cloud-based, multi-voice)
48
+ - Kokoro TTS (Multi-language, lightweight, local)
49
+ - Style-Bert-VITS2 (Local, high-quality Japanese TTS)
50
+
51
+ - **Unified Interface**: Switch between different TTS engines without changing your code
52
+ - **Streaming Support**: Real-time audio streaming for supported engines
53
+ - **Decoupled Architecture**: Use TTS engines, audio players, and file writers independently
54
+ - **Audio Playback**: Synchronous audio player with streaming support
55
+ - **File Export**: Save synthesized speech to various audio formats
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ pip install speechflow
61
+ ```
62
+
63
+ For Style-Bert-VITS2 support:
64
+ ```bash
65
+ # Make sure numba>=0.61 is installed first for Python 3.12 compatibility
66
+ pip install numba>=0.61
67
+ pip install style-bert-vits2>=2.5.0
68
+ ```
69
+
70
+ ## Quick Start
71
+
72
+ ### Basic Usage (Decoupled Components)
73
+ ```python
74
+ from speechflow import OpenAITTSEngine, AudioPlayer, AudioWriter
75
+
76
+ # Initialize components
77
+ engine = OpenAITTSEngine(api_key="your-api-key")
78
+ player = AudioPlayer()
79
+ writer = AudioWriter()
80
+
81
+ # Generate audio
82
+ audio = engine.get("Hello, world!")
83
+
84
+ # Play audio
85
+ player.play(audio)
86
+
87
+ # Save to file
88
+ writer.save(audio, "output.wav")
89
+ ```
90
+
91
+ ### Streaming Audio
92
+
93
+ **Important Notes on Streaming Behavior:**
94
+ - **OpenAI**: True streaming with multiple chunks. First call may have 10-20s cold start delay. Uses PCM format for simplicity.
95
+ - **Gemini**: Returns complete audio in a single chunk (as of January 2025). This is a known limitation, not true streaming.
96
+
97
+ ```python
98
+ from speechflow import OpenAITTSEngine, AudioPlayer, AudioWriter
99
+
100
+ # Initialize components
101
+ engine = OpenAITTSEngine(api_key="your-api-key")
102
+ player = AudioPlayer()
103
+ writer = AudioWriter()
104
+
105
+ # Warmup for OpenAI (recommended for production)
106
+ _ = list(engine.stream("Warmup"))
107
+
108
+ # Stream and play audio (returns combined AudioData)
109
+ combined_audio = player.play_stream(engine.stream("This is a long text that will be streamed..."))
110
+
111
+ # Save the combined audio to file
112
+ writer.save(combined_audio, "output.wav")
113
+ ```
114
+
115
+ ## Engine-Specific Features
116
+
117
+ ### OpenAI TTS
118
+ ```python
119
+ from speechflow import OpenAITTSEngine
120
+
121
+ engine = OpenAITTSEngine(api_key="your-api-key")
122
+ audio = engine.get(
123
+ "Hello",
124
+ voice="alloy", # or: ash, ballad, coral, echo, fable, nova, onyx, sage, shimmer
125
+ model="gpt-4o-mini-tts", # or: tts-1, tts-1-hd
126
+ speed=1.0
127
+ )
128
+
129
+ # Streaming
130
+ for chunk in engine.stream("Long text..."):
131
+ # Process audio chunks in real-time
132
+ pass
133
+ ```
134
+
135
+ ### Google Gemini TTS
136
+ ```python
137
+ from speechflow import GeminiTTSEngine
138
+
139
+ engine = GeminiTTSEngine(api_key="your-api-key")
140
+ audio = engine.get(
141
+ "Hello",
142
+ model="gemini-2.5-flash-preview-tts", # or: gemini-2.5-pro-preview-tts
143
+ voice="Leda", # or: Puck, Charon, Kore, Fenrir, Aoede, and many more
144
+ speed=1.0
145
+ )
146
+ ```
147
+
148
+ ### FishAudio TTS
149
+ ```python
150
+ from speechflow import FishAudioTTSEngine
151
+
152
+ engine = FishAudioTTSEngine(api_key="your-api-key")
153
+ audio = engine.get(
154
+ "Hello world",
155
+ model="s1", # or: s1-mini, speech-1.6, speech-1.5, agent-x0
156
+ voice="your-voice-id" # Use your FishAudio voice ID
157
+ )
158
+
159
+ # Streaming
160
+ for chunk in engine.stream("Streaming text..."):
161
+ # Process audio chunks
162
+ pass
163
+ ```
164
+
165
+ ### Kokoro TTS
166
+ ```python
167
+ from speechflow import KokoroTTSEngine
168
+
169
+ # Default: American English
170
+ engine = KokoroTTSEngine()
171
+ audio = engine.get(
172
+ "Hello world",
173
+ voice="af_heart" # Multiple voices available
174
+ )
175
+
176
+ # Japanese (requires additional setup)
177
+ engine = KokoroTTSEngine(lang_code="j")
178
+ audio = engine.get(
179
+ "こんにちは、世界",
180
+ voice="af_heart"
181
+ )
182
+ ```
183
+
184
+ **Note for Japanese support:**
185
+ The Japanese dictionary will be automatically downloaded on first use.
186
+ If you encounter errors, you can manually download it:
187
+ ```bash
188
+ python -m unidic download
189
+ ```
190
+
191
+ ### Style-Bert-VITS2
192
+ ```python
193
+ from speechflow import StyleBertTTSEngine
194
+
195
+ # Use pre-trained model (automatically downloads on first use)
196
+ engine = StyleBertTTSEngine(model_name="jvnv-F1-jp") # Female Japanese voice
197
+ audio = engine.get(
198
+ "こんにちは、世界",
199
+ style="Happy", # Emotion: Neutral, Happy, Sad, Angry, Fear, Surprise, Disgust
200
+ style_weight=5.0, # Emotion strength (0.0-10.0)
201
+ speed=1.0, # Speech speed
202
+ pitch=0.0 # Pitch shift in semitones
203
+ )
204
+
205
+ # Available pre-trained models:
206
+ # - jvnv-F1-jp, jvnv-F2-jp: Female voices (JP-Extra version)
207
+ # - jvnv-M1-jp, jvnv-M2-jp: Male voices (JP-Extra version)
208
+ # - jvnv-F1, jvnv-F2, jvnv-M1, jvnv-M2: Legacy versions
209
+
210
+ # Use custom model
211
+ engine = StyleBertTTSEngine(model_path="/path/to/your/model")
212
+
213
+ # Sentence-by-sentence streaming (not true streaming)
214
+ for audio_chunk in engine.stream("長い文章を文ごとに生成します。"):
215
+ # Process each sentence's audio
216
+ pass
217
+ ```
218
+
219
+ **Note:** Style-Bert-VITS2 is optimized for Japanese text and requires GPU for best performance.
220
+
221
+ ## Language Support
222
+
223
+ ### Kokoro Languages
224
+ - 🇺🇸 American English (`a`)
225
+ - 🇬🇧 British English (`b`)
226
+ - 🇪🇸 Spanish (`e`)
227
+ - 🇫🇷 French (`f`)
228
+ - 🇮🇳 Hindi (`h`)
229
+ - 🇮🇹 Italian (`i`)
230
+ - 🇯🇵 Japanese (`j`) - requires unidic
231
+ - 🇧🇷 Brazilian Portuguese (`p`)
232
+ - 🇨🇳 Mandarin Chinese (`z`)
233
+
234
+ ## License
235
+
236
+ MIT