termux-tts 0.1.1 → 1.3.0

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.
package/docs/guide.md CHANGED
@@ -31,7 +31,7 @@ flowchart TD
31
31
  end
32
32
 
33
33
  subgraph Hardware_Probe ["하드웨어 진단 계층"]
34
- Doctor[VulkanDoctor (vulkan_probe.py)] --> AVR[ameva-vulkan-runtime (12-Stage Probe)]
34
+ Doctor[VulkanDoctor (vulkan_probe.py)] --> AVR[ameva-runtime (12-Stage Probe)]
35
35
  end
36
36
  ```
37
37
 
@@ -42,7 +42,7 @@ flowchart TD
42
42
  2. **Option B (안드로이드 시스템 네이티브 음성 브릿지 - `NativeAndroidEngine`)**:
43
43
  - 삼성 보이스(Samsung Voice) 및 구글 음성 엔진(Google TTS)과 Termux IPC로 직접 통신하여 zero-download 오버헤드로 즉시 물리 스피커 발화를 수행합니다.
44
44
  3. **Vulkan GPU 진단 계층 (`VulkanDoctor`)**:
45
- - `ameva-vulkan-runtime`의 12단계 자체 검증 엔진(V0~V11)을 바인딩하여 퀄컴 Adreno/ARM Mali GPU의 파이프라인 가용성을 실시간 판별합니다.
45
+ - `ameva-runtime`의 12단계 자체 검증 엔진(V0~V11)을 바인딩하여 퀄컴 Adreno/ARM Mali GPU의 파이프라인 가용성을 실시간 판별합니다.
46
46
 
47
47
  ---
48
48
 
@@ -66,7 +66,7 @@ fi
66
66
 
67
67
  # [2/4] Python SDK 및 CLI 설치 (Editable/Release Build)
68
68
  pip install --upgrade pip setuptools wheel
69
- pip install ameva-vulkan-runtime || true
69
+ pip install ameva-runtime || true
70
70
  pip install --no-build-isolation -e .
71
71
 
72
72
  # [3/4] Node.js SDK 및 글로벌 npm CLI 심볼릭 링크
@@ -81,7 +81,7 @@ termux-tts doctor || true
81
81
  ### 2.2 패키지 빌드 메타데이터 (`setup.py` & `package.json`)
82
82
  - **Python Packaging (`setup.py`)**:
83
83
  - `console_scripts` 엔트리포인트를 통해 시스템 전역에 `termux-tts` CLI 명령어를 등록합니다.
84
- - `numpy>=1.20.0` 및 `ameva-vulkan-runtime>=1.0.0`을 표준 종속성으로 선언합니다.
84
+ - `numpy>=1.20.0` 및 `ameva-runtime>=2.0.0`을 표준 종속성으로 선언합니다.
85
85
  - **Node.js Packaging (`package.json`)**:
86
86
  - `bin/cli.js`를 전역 실행 바이너리로 연결하고, CommonJS 기반 `index.js` 모듈을 제공합니다.
87
87
 
@@ -378,7 +378,7 @@ class NativeAndroidEngine:
378
378
  ---
379
379
 
380
380
  ### 3.6 하드웨어 진단 프로브 (`termux_tts/vulkan_probe.py`)
381
- 공식 `ameva-vulkan-runtime` 패키지를 바인딩하여 12단계 하드웨어 정밀 진단을 구동합니다.
381
+ 공식 `ameva-runtime` 패키지를 바인딩하여 12단계 하드웨어 정밀 진단을 구동합니다.
382
382
 
383
383
  - **V0**: `libvulkan.so` 동적 로더 개방 여부
384
384
  - **V1~V3**: GPU 인스턴스 및 물리 디바이스(Adreno/Mali) 질의
package/docs/tts_guide.md CHANGED
@@ -31,7 +31,7 @@ flowchart TD
31
31
  end
32
32
 
33
33
  subgraph Hardware_Probe ["하드웨어 진단 계층"]
34
- Doctor[VulkanDoctor (vulkan_probe.py)] --> AVR[ameva-vulkan-runtime (12-Stage Probe)]
34
+ Doctor[VulkanDoctor (vulkan_probe.py)] --> AVR[ameva-runtime (12-Stage Probe)]
35
35
  end
36
36
  ```
37
37
 
@@ -42,7 +42,7 @@ flowchart TD
42
42
  2. **Option B (안드로이드 시스템 네이티브 음성 브릿지 - `NativeAndroidEngine`)**:
43
43
  - 삼성 보이스(Samsung Voice) 및 구글 음성 엔진(Google TTS)과 Termux IPC로 직접 통신하여 zero-download 오버헤드로 즉시 물리 스피커 발화를 수행합니다.
44
44
  3. **Vulkan GPU 진단 계층 (`VulkanDoctor`)**:
45
- - `ameva-vulkan-runtime`의 12단계 자체 검증 엔진(V0~V11)을 바인딩하여 퀄컴 Adreno/ARM Mali GPU의 파이프라인 가용성을 실시간 판별합니다.
45
+ - `ameva-runtime`의 12단계 자체 검증 엔진(V0~V11)을 바인딩하여 퀄컴 Adreno/ARM Mali GPU의 파이프라인 가용성을 실시간 판별합니다.
46
46
 
47
47
  ---
48
48
 
@@ -66,7 +66,7 @@ fi
66
66
 
67
67
  # [2/4] Python SDK 및 CLI 설치 (Editable/Release Build)
68
68
  pip install --upgrade pip setuptools wheel
69
- pip install ameva-vulkan-runtime || true
69
+ pip install ameva-runtime || true
70
70
  pip install --no-build-isolation -e .
71
71
 
72
72
  # [3/4] Node.js SDK 및 글로벌 npm CLI 심볼릭 링크
@@ -81,7 +81,7 @@ termux-tts doctor || true
81
81
  ### 2.2 패키지 빌드 메타데이터 (`setup.py` & `package.json`)
82
82
  - **Python Packaging (`setup.py`)**:
83
83
  - `console_scripts` 엔트리포인트를 통해 시스템 전역에 `termux-tts` CLI 명령어를 등록합니다.
84
- - `numpy>=1.20.0` 및 `ameva-vulkan-runtime>=1.0.0`을 표준 종속성으로 선언합니다.
84
+ - `numpy>=1.20.0` 및 `ameva-runtime>=2.0.0`을 표준 종속성으로 선언합니다.
85
85
  - **Node.js Packaging (`package.json`)**:
86
86
  - `bin/cli.js`를 전역 실행 바이너리로 연결하고, CommonJS 기반 `index.js` 모듈을 제공합니다.
87
87
 
@@ -378,7 +378,7 @@ class NativeAndroidEngine:
378
378
  ---
379
379
 
380
380
  ### 3.6 하드웨어 진단 프로브 (`termux_tts/vulkan_probe.py`)
381
- 공식 `ameva-vulkan-runtime` 패키지를 바인딩하여 12단계 하드웨어 정밀 진단을 구동합니다.
381
+ 공식 `ameva-runtime` 패키지를 바인딩하여 12단계 하드웨어 정밀 진단을 구동합니다.
382
382
 
383
383
  - **V0**: `libvulkan.so` 동적 로더 개방 여부
384
384
  - **V1~V3**: GPU 인스턴스 및 물리 디바이스(Adreno/Mali) 질의
package/install.sh CHANGED
@@ -26,10 +26,10 @@ fi
26
26
  # 2. Python Toolchain & Package Installation (pip)
27
27
  echo "[2/4] Installing Python SDK and CLI via pip..."
28
28
  pip install --upgrade pip setuptools wheel
29
- if pip install ameva-vulkan-runtime 2>/dev/null; then
30
- echo " -> ameva-vulkan-runtime hardware diagnostics bound."
29
+ if pip install ameva-runtime 2>/dev/null; then
30
+ echo " -> ameva-runtime hardware diagnostics bound."
31
31
  else
32
- echo " -> ameva-vulkan-runtime optional hardware acceleration bridge skipped."
32
+ echo " -> ameva-runtime optional hardware acceleration bridge skipped."
33
33
  fi
34
34
  pip install --no-build-isolation -e .
35
35
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "termux-tts",
3
- "version": "0.1.1",
3
+ "version": "1.3.0",
4
4
  "description": "On-device Text-to-Speech framework utilizing device resources (DSP Formant Vocoder, ONNX Neural Runtime & Android Native Voice)",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -23,7 +23,7 @@
23
23
  "author": "AMEVA Foundation",
24
24
  "license": "Apache-2.0",
25
25
  "dependencies": {
26
- "ameva-vulkan-runtime": ">=1.0.0"
26
+ "@ameva/runtime": ">=2.1.0"
27
27
  },
28
28
  "engines": {
29
29
  "node": ">=16.0.0"
package/pyproject.toml CHANGED
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "termux-tts"
7
- version = "1.1.3"
8
- description = "On-device Text-to-Speech framework utilizing device resources (DSP Formant Vocoder, ONNX Neural Runtime & Android Native Voice Bridge)"
7
+ version = "1.3.0"
8
+ description = "On-device 4-Tier Text-to-Speech framework utilizing device resources (DSP Formant Vocoder, C++ Sherpa-ONNX Neural, Android Native & Expressive)"
9
9
  readme = "README.pypi.md"
10
10
  requires-python = ">=3.10"
11
11
  license = { text = "Apache-2.0" }
@@ -25,6 +25,7 @@ classifiers = [
25
25
  ]
26
26
  dependencies = [
27
27
  "numpy>=1.20.0",
28
+ "ameva-component-sdk>=0.1.0,<2.0",
28
29
  ]
29
30
 
30
31
  [project.optional-dependencies]
package/setup.py CHANGED
@@ -3,8 +3,8 @@ from setuptools import setup, find_packages
3
3
 
4
4
  setup(
5
5
  name="termux-tts",
6
- version="1.1.3",
7
- description="Ultra-Fast On-Device Dual-Engine Text-to-Speech Framework (Parametric Formant Acoustic Synthesizer & Android Native Voice Bridge)",
6
+ version="1.2.0",
7
+ description="Ultra-Fast On-Device 4-Tier Text-to-Speech Framework (DSP Synth, Android Native, C++ Sherpa-ONNX Neural & Expressive)",
8
8
  long_description=open("README.pypi.md", encoding="utf-8").read() if os.path.exists("README.pypi.md") else open("README.md", encoding="utf-8").read(),
9
9
  long_description_content_type="text/markdown",
10
10
  author="AMEVA Foundation",
@@ -14,7 +14,7 @@ setup(
14
14
  python_requires=">=3.8",
15
15
  install_requires=[
16
16
  "numpy>=1.20.0",
17
- "ameva-vulkan-runtime>=1.0.0",
17
+ "ameva-runtime>=2.0.0",
18
18
  ],
19
19
  extras_require={
20
20
  "onnx": ["onnxruntime>=1.15.0"],
@@ -1,47 +1,63 @@
1
- """
2
- termux-tts: Production-Grade Dual-Engine TTS Framework for Android Termux.
3
- - Option A: Deep Learning VITS ONNX Neural Vocoder (Vulkan GPU Accelerated)
4
- - Option B: Android System Native Voice Engine Bridge (Samsung / Google Voice)
5
- """
6
-
7
- from .engine import TTSEngine, load, doctor
8
- from .engine_native import NativeAndroidEngine, NativeResult
9
- from .engine_dsp import ParametricDSPEngine, DSPResult, QUALITY_PRESETS, DSPSynthesizer
10
- from .engine_onnx import ONNXNeuralEngine, ONNXResult
11
- from .tokenizer import PhoneticTokenizer, EXPRESSIVE_TAGS
12
- from .g2p_korean import KoreanG2PEngine, korean_text_to_phonemes
13
- from .audio import AudioBuffer
14
- from .exceptions import (
15
- TTSError,
16
- TTSModelLoadError,
17
- TTSInferenceError,
18
- VulkanInitializationError,
19
- TTSAudioEncodingError,
20
- TTSLanguageNotSupportedError
21
- )
22
-
23
- __version__ = "1.1.2"
24
- __all__ = [
25
- "TTSEngine",
26
- "load",
27
- "doctor",
28
- "ParametricDSPEngine",
29
- "DSPSynthesizer",
30
- "DSPResult",
31
- "NativeAndroidEngine",
32
- "NativeResult",
33
- "ONNXNeuralEngine",
34
- "ONNXResult",
35
- "QUALITY_PRESETS",
36
- "PhoneticTokenizer",
37
- "KoreanG2PEngine",
38
- "korean_text_to_phonemes",
39
- "EXPRESSIVE_TAGS",
40
- "AudioBuffer",
41
- "TTSError",
42
- "TTSModelLoadError",
43
- "TTSInferenceError",
44
- "VulkanInitializationError",
45
- "TTSAudioEncodingError",
46
- "TTSLanguageNotSupportedError"
47
- ]
1
+ """
2
+ termux-tts: Production-Grade 4-Tier TTS Framework for Android Termux.
3
+ - Tier 1: Parametric DSP Formant Synthesizer Engine (0MB Zero-Dependency)
4
+ - Tier 2: Android System Native Voice Engine Bridge (Samsung / Google Voice)
5
+ - Tier 3: Authentic C++ Subprocess-Isolated Sherpa-ONNX Neural Vocoder (VITS Deep Learning)
6
+ - Tier 4: Pure On-Device Expressive Emotional Synthesizer (Conversational Tags)
7
+ """
8
+
9
+ from .engine import TTSEngine, load, doctor
10
+ from .engine_native import NativeAndroidEngine, NativeResult
11
+ from .engine_dsp import ParametricDSPEngine, DSPResult, QUALITY_PRESETS, DSPSynthesizer
12
+ from .engine_sherpa import SherpaNeuralEngine, SherpaResult
13
+ from .engine_vulkan import VulkanNeuralEngine, VulkanResult
14
+ from .engine_expressive import ExpressiveEngine, ExpressiveResult
15
+ from .installer import run_installation
16
+ from .tokenizer import PhoneticTokenizer, EXPRESSIVE_TAGS
17
+ from .g2p_korean import KoreanG2PEngine, korean_text_to_phonemes
18
+ from .audio import AudioBuffer
19
+ from .exceptions import (
20
+ TTSError,
21
+ TTSModelLoadError,
22
+ TTSInferenceError,
23
+ VulkanInitializationError,
24
+ TTSAudioEncodingError,
25
+ TTSLanguageNotSupportedError
26
+ )
27
+
28
+ # Backward-compatibility alias
29
+ ONNXNeuralEngine = SherpaNeuralEngine
30
+ ONNXResult = SherpaResult
31
+
32
+ __version__ = "1.3.0"
33
+ __all__ = [
34
+ "TTSEngine",
35
+ "load",
36
+ "doctor",
37
+ "ParametricDSPEngine",
38
+ "DSPSynthesizer",
39
+ "DSPResult",
40
+ "NativeAndroidEngine",
41
+ "NativeResult",
42
+ "SherpaNeuralEngine",
43
+ "SherpaResult",
44
+ "VulkanNeuralEngine",
45
+ "VulkanResult",
46
+ "ExpressiveEngine",
47
+ "ExpressiveResult",
48
+ "run_installation",
49
+ "ONNXNeuralEngine",
50
+ "ONNXResult",
51
+ "QUALITY_PRESETS",
52
+ "PhoneticTokenizer",
53
+ "KoreanG2PEngine",
54
+ "korean_text_to_phonemes",
55
+ "EXPRESSIVE_TAGS",
56
+ "AudioBuffer",
57
+ "TTSError",
58
+ "TTSModelLoadError",
59
+ "TTSInferenceError",
60
+ "VulkanInitializationError",
61
+ "TTSAudioEncodingError",
62
+ "TTSLanguageNotSupportedError"
63
+ ]
@@ -2,12 +2,21 @@
2
2
  termux_tts.adapter
3
3
  ===================
4
4
  AMEVA Component Protocol v1 — Orchestrator Adapter (v0.8.1 호환)
5
+
6
+ P0-2: infer() fallback yield _not_supported → raise OperationNotSupported
7
+ P0-4: except Exception → retryable 분류, 원본 오류 코드 보존
5
8
  """
6
9
  from __future__ import annotations
7
10
 
8
11
  from typing import Any, AsyncIterator
9
12
 
10
13
  from ameva_component.adapter_base import BaseOrchestratorAdapter
14
+ from ameva_component.exceptions import (
15
+ ComponentError,
16
+ OperationNotSupported,
17
+ redact_details,
18
+ redact_text,
19
+ )
11
20
  from termux_tts.control.component import TTSControl
12
21
 
13
22
 
@@ -15,12 +24,25 @@ class TTSOrchestratorAdapter(BaseOrchestratorAdapter):
15
24
  """TTS (Text-to-Speech) Orchestrator Adapter.
16
25
 
17
26
  합성은 파일 기반으로 수행됩니다.
18
- infer()는 text를 받아 audio 파일 경로를 반환합니다.
27
+ infer(): text를 받아 audio 파일 경로를 반환합니다.
19
28
  요청 모델과 실행 모델이 다르면 fallback_used=True를 명시합니다.
20
29
  """
21
30
 
22
31
  COMPONENT_ID = "termux-tts"
23
32
 
33
+ _RETRYABLE_CODES: frozenset[str] = frozenset({
34
+ "REMOTE_TIMEOUT",
35
+ "MODEL_BUSY",
36
+ "TEMPORARY_RESOURCE_UNAVAILABLE",
37
+ })
38
+ _NON_RETRYABLE_CODES: frozenset[str] = frozenset({
39
+ "VOICE_NOT_FOUND",
40
+ "TEXT_TOO_LONG",
41
+ "UNSUPPORTED_LANGUAGE",
42
+ "OUTPUT_PATH_FORBIDDEN",
43
+ "ENCODING_FAILED",
44
+ })
45
+
24
46
  def __init__(self, control: TTSControl | None = None) -> None:
25
47
  self._control = control or TTSControl()
26
48
 
@@ -28,14 +50,14 @@ class TTSOrchestratorAdapter(BaseOrchestratorAdapter):
28
50
  """TTS synthesis: text → audio file path.
29
51
 
30
52
  request 키:
31
- text (str): 합성할 텍스트 (필수)
53
+ text (str): 합성할 텍스트 (필수, 비어있으면 안 됨)
32
54
  voice_id (str): 목소리 ID (선택)
33
55
  model_id (str): 모델 ID (선택)
34
- output_path (str): 출력 파일 경로 (선택, 없으면 임시 파일)
56
+ output_path (str): 출력 파일 경로 (선택)
35
57
 
36
58
  반환 프레임:
37
59
  {"type": "audio", "audio_path": str, "final": bool, "fallback_used": bool}
38
- {"type": "error", "code": str, "message": str}
60
+ {"type": "error", "ok": False, "error": {...}}
39
61
  """
40
62
  text = request.get("text", "").strip()
41
63
  if not text:
@@ -52,46 +74,127 @@ class TTSOrchestratorAdapter(BaseOrchestratorAdapter):
52
74
  }
53
75
  return
54
76
 
55
- if hasattr(self._control, "synthesize"):
56
- try:
57
- result = await self._control.synthesize(request)
58
- audio_path = result.get("audio_path", "")
59
- if not audio_path:
60
- yield {
61
- "type": "error",
62
- "ok": False,
63
- "error": {
64
- "code": "SYNTHESIS_FAILED",
65
- "message": "synthesize() returned no audio_path",
66
- "operation": "infer",
67
- "component_id": self.COMPONENT_ID,
68
- "retryable": True,
69
- },
70
- }
71
- return
72
- yield {
73
- "type": "audio",
74
- "audio_path": audio_path,
75
- "final": True,
76
- "fallback_used": result.get("fallback_used", False),
77
- "requested_voice": result.get("requested_voice"),
78
- "executed_voice": result.get("executed_voice"),
79
- "ok": True,
80
- }
81
- except Exception as exc:
77
+ if not hasattr(self._control, "synthesize"):
78
+ # P0-2: fallback yield → raise
79
+ raise OperationNotSupported(operation="infer.synthesize", component_id=self.COMPONENT_ID)
80
+
81
+ try:
82
+ result = await self._control.synthesize(request)
83
+
84
+ if not isinstance(result, dict):
85
+ raise ValueError(f"synthesize() must return dict, got {type(result).__name__}")
86
+
87
+ if result.get("ok") is not True:
88
+ err_payload = result.get("error") if isinstance(result.get("error"), dict) else {}
82
89
  yield {
83
90
  "type": "error",
84
91
  "ok": False,
85
92
  "error": {
86
- "code": "SYNTHESIS_FAILED",
87
- "message": str(exc),
93
+ "code": err_payload.get("code", "ADAPTER_RESULT_NOT_SUCCESS"),
94
+ "message": err_payload.get("message", "synthesize() did not return ok=True"),
88
95
  "operation": "infer",
89
96
  "component_id": self.COMPONENT_ID,
90
- "retryable": True,
97
+ "retryable": False,
98
+ "details": {"result_keys": sorted(result.keys())},
91
99
  },
92
100
  }
93
- else:
94
- yield self._not_supported("infer.synthesize")
101
+ return
102
+
103
+ audio_path = result.get("audio_path")
104
+ if not audio_path:
105
+ raise ValueError("synthesize() result missing required field 'audio_path'")
106
+ if not isinstance(audio_path, str):
107
+ raise TypeError(f"synthesize() audio_path must be str, got {type(audio_path).__name__}")
108
+
109
+ yield {
110
+ "type": "audio",
111
+ "audio_path": audio_path,
112
+ "final": True,
113
+ "fallback_used": result.get("fallback_used", False),
114
+ "requested_voice": result.get("requested_voice"),
115
+ "executed_voice": result.get("executed_voice"),
116
+ "ok": True,
117
+ }
118
+
119
+ except ComponentError as component_err:
120
+ # HIGH 1: ComponentError public_message와 redact_details로 외부 노출 보안 격리
121
+ import logging
122
+ logging.getLogger(__name__).exception(
123
+ "TTS component operation failed",
124
+ extra={
125
+ "component_id": self.COMPONENT_ID,
126
+ "operation": "infer",
127
+ "code": getattr(component_err, "code", "COMPONENT_ERROR"),
128
+ },
129
+ )
130
+ if hasattr(component_err, "to_public_dict"):
131
+ err_dict = component_err.to_public_dict()
132
+ else:
133
+ err_dict = {
134
+ "code": getattr(component_err, "code", "COMPONENT_ERROR"),
135
+ "message": redact_text(getattr(component_err, "public_message", "Component operation failed")),
136
+ "retryable": getattr(component_err, "retryable", False),
137
+ "details": redact_details(getattr(component_err, "details", {})),
138
+ }
139
+ yield {
140
+ "type": "error",
141
+ "ok": False,
142
+ "error": {
143
+ **err_dict,
144
+ "operation": "infer",
145
+ "component_id": self.COMPONENT_ID,
146
+ "retryable": self._classify_retryable(
147
+ err_dict.get("code", ""), default=err_dict.get("retryable", False)
148
+ ),
149
+ },
150
+ }
151
+
152
+ except (ValueError, TypeError) as contract_err:
153
+ # P0-3/4 & HIGH 1: 계약 위반 (str(contract_err) 직접 노출 금지, 내부 로그 격리)
154
+ import logging
155
+ logging.getLogger(__name__).exception("TTS contract validation error during infer: %s", contract_err)
156
+ yield {
157
+ "type": "error",
158
+ "ok": False,
159
+ "error": {
160
+ "code": "ADAPTER_CONTRACT_ERROR",
161
+ "message": "Adapter contract validation failed",
162
+ "operation": "infer",
163
+ "component_id": self.COMPONENT_ID,
164
+ "retryable": False,
165
+ "details": {
166
+ "cause_type": type(contract_err).__name__,
167
+ "operation": "infer",
168
+ },
169
+ },
170
+ }
171
+
172
+ except Exception as unexpected_err:
173
+ import logging
174
+ logging.getLogger(__name__).exception("TTS adapter unexpected error during infer: %s", unexpected_err)
175
+ code = getattr(unexpected_err, "code", "ADAPTER_INTERNAL_ERROR")
176
+ yield {
177
+ "type": "error",
178
+ "ok": False,
179
+ "error": {
180
+ "code": code if isinstance(code, str) else "ADAPTER_INTERNAL_ERROR",
181
+ "message": "Unexpected adapter failure",
182
+ "operation": "infer",
183
+ "component_id": self.COMPONENT_ID,
184
+ "retryable": False,
185
+ "details": {
186
+ "cause_type": type(unexpected_err).__name__,
187
+ "operation": "infer",
188
+ },
189
+ },
190
+ }
191
+
192
+ def _classify_retryable(self, code: str, *, default: bool = False) -> bool:
193
+ if code in self._RETRYABLE_CODES:
194
+ return True
195
+ if code in self._NON_RETRYABLE_CODES:
196
+ return False
197
+ return default
95
198
 
96
199
 
97
200
  def create_adapter() -> TTSOrchestratorAdapter:
@@ -46,7 +46,8 @@ class AudioBuffer:
46
46
 
47
47
  def to_pcm16_bytes(self) -> bytes:
48
48
  """Convert float32 [-1.0, 1.0] samples into 16-bit signed integer bytes."""
49
- clipped = np.clip(self.samples, -1.0, 1.0)
49
+ clean = np.nan_to_num(self.samples, nan=0.0, posinf=1.0, neginf=-1.0)
50
+ clipped = np.clip(clean, -1.0, 1.0)
50
51
  pcm16 = (clipped * 32767.0).astype(np.int16)
51
52
  return pcm16.tobytes()
52
53
 
@@ -64,6 +65,28 @@ class AudioBuffer:
64
65
  except Exception as e:
65
66
  raise TTSAudioEncodingError(f"Failed to encode WAV buffer: {e}") from e
66
67
 
68
+ def pad_silence(self, lead_in_ms: int = 200, lead_out_ms: int = 150) -> "AudioBuffer":
69
+ """Prepend and append true zero-amplitude silence to prevent Android DAC ramp-up clipping."""
70
+ lead_in_samples = int(self.sample_rate * (lead_in_ms / 1000.0))
71
+ lead_out_samples = int(self.sample_rate * (lead_out_ms / 1000.0))
72
+ zeros_in = np.zeros(lead_in_samples, dtype=np.float32)
73
+ zeros_out = np.zeros(lead_out_samples, dtype=np.float32)
74
+ padded = np.concatenate([zeros_in, self.samples, zeros_out])
75
+ return AudioBuffer(padded, sample_rate=self.sample_rate)
76
+
77
+ @classmethod
78
+ def from_wav_file(cls, filepath: str) -> "AudioBuffer":
79
+ """Load an AudioBuffer directly from a WAV file on disk."""
80
+ try:
81
+ with wave.open(filepath, "rb") as wf:
82
+ sr = wf.getframerate()
83
+ frames = wf.readframes(wf.getnframes())
84
+ pcm16 = np.frombuffer(frames, dtype=np.int16)
85
+ samples = (pcm16 / 32767.0).astype(np.float32)
86
+ return cls(samples, sample_rate=sr)
87
+ except Exception as e:
88
+ raise TTSAudioEncodingError(f"Failed to read WAV file '{filepath}': {e}") from e
89
+
67
90
  def save(self, filepath: str) -> str:
68
91
  """Save the audio buffer to a WAV file on disk."""
69
92
  wav_data = self.to_wav_bytes()