Files
kokoro-wayland/narrate.py
2026-02-04 17:09:36 +05:30

25 lines
721 B
Python

import sounddevice as sd
from kokoro import KPipeline
import torch
# Check if we are actually using your RTX 3050
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Using device: {device}")
# Initialize pipeline with the specific Python 3.12 environment
pipeline = KPipeline(lang_code="a", device=device)
text = """
The RTX 3050 is now narrating this documentation.
Using uv and Python 3.12 ensures that we avoid the build errors
commonly found on Arch Linux's bleeding-edge Python 3.14.
"""
# Generating audio
generator = pipeline(text, voice="af_heart", speed=1.1)
for i, (gs, ps, audio) in enumerate(generator):
print(f"Playing chunk {i}...")
sd.play(audio, samplerate=24000)
sd.wait()