lamp: narration (pocket_tts, azelma, 24 kHz, 0.6 s gaps)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FAqjv3n4yABxvJPJHFRhVA
This commit is contained in:
teahubxyzandClaude Fable 5.1 committed 2026-10-28 04:47:30 +00:00
1 parent 6058774c9c
commit 12d0099659
1 file changed
+18
+18
View File
@@ -0,0 +1,18 @@
import json, numpy as np
from pocket_tts import TTSModel
S = json.load(open('script.json'))
import pocket_tts, pathlib; m = TTSModel.load_model(config=str(pathlib.Path(pocket_tts.__file__).parent / 'config' / 'english_2026-01.yaml'))
assert int(m.sample_rate) == 24000
st = m.get_state_for_audio_prompt('azelma')
gap = np.zeros(int(0.6 * 24000), dtype='<i2')
D, chunks = [], []
for i, t in enumerate(S):
parts = [(s.detach().cpu().numpy().clip(-1, 1) * 32767).astype('<i2') for s in m.generate_audio_stream(st, t, copy_state=True)]
a = np.concatenate(parts)
D.append(round(len(a) / 24000, 3)); chunks.append(a)
if i < len(S) - 1: chunks.append(gap)
print(i, D[-1], flush=True)
full = np.concatenate(chunks)
open('lamp.pcm', 'wb').write(full.tobytes())
json.dump(D, open('durations.json', 'w'))
print('total', round(len(full) / 24000, 2), flush=True)