mirror of
https://github.com/sortedcord/kokoro-wayland.git
synced 2026-03-07 15:44:07 +05:30
Initial Upload
This commit is contained in:
29
wayland_narrate.py
Normal file
29
wayland_narrate.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import subprocess
|
||||
import sounddevice as sd
|
||||
from kokoro import KPipeline
|
||||
import torch
|
||||
import sys
|
||||
|
||||
# 1. Fetch text from Wayland Primary Selection (highlighted text)
|
||||
try:
|
||||
# 'wl-paste -p' gets the current mouse highlight
|
||||
text = subprocess.check_output(["wl-paste", "-p"], text=True).strip()
|
||||
except Exception:
|
||||
print("Nothing highlighted or wl-clipboard not installed.")
|
||||
sys.exit(1)
|
||||
|
||||
if not text:
|
||||
print("Selection is empty.")
|
||||
sys.exit(0)
|
||||
|
||||
print(f"Narrating: {text[:50]}...")
|
||||
|
||||
# 2. Setup Kokoro (GPU)
|
||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||
pipeline = KPipeline(lang_code="a", device=device)
|
||||
|
||||
# 3. Generate and Play
|
||||
generator = pipeline(text, voice="af_heart", speed=1.1)
|
||||
for i, (gs, ps, audio) in enumerate(generator):
|
||||
sd.play(audio, 24000)
|
||||
sd.wait()
|
||||
Reference in New Issue
Block a user