[结束提示音]:完成对话结束音效提示,包含本地短音生成、恢复待机播放和配置测试

This commit is contained in:
mkbk
2026-06-18 13:59:12 +08:00
parent ac72738fc8
commit 80549fb312
12 changed files with 130 additions and 23 deletions
+30
View File
@@ -144,6 +144,36 @@ def _normalize_spoken_text(text: str) -> str:
return clean.strip(" \t\r\n,;:")
def make_prompt_chime(
*,
frequency_hz: int = 880,
duration_ms: int = 140,
sample_rate: int = 16000,
channels: int = 1,
) -> AudioSegment:
duration_ms = max(20, duration_ms)
sample_rate = max(8000, sample_rate)
channels = max(1, channels)
samples = int(sample_rate * duration_ms / 1000)
fade_samples = max(1, min(samples // 2, int(sample_rate * 0.015)))
pcm = bytearray()
for idx in range(samples):
fade_in = idx / fade_samples if idx < fade_samples else 1.0
fade_out = (samples - idx - 1) / fade_samples if idx >= samples - fade_samples else 1.0
envelope = max(0.0, min(1.0, fade_in, fade_out))
value = int(math.sin(2 * math.pi * frequency_hz * idx / sample_rate) * 9000 * envelope)
packed = struct.pack("<h", value)
pcm.extend(packed * channels)
return AudioSegment(
bytes(pcm),
sample_rate,
channels,
0,
duration_ms,
{"chime": "end", "text": "end_chime"},
)
class SentenceBuffer:
def __init__(self, max_chars: int = 80) -> None:
self.max_chars = max_chars