Skip to content

A TTS that fits in your CPU (and pocket)

Python

Adding possibility to read the input text from stdin in the CLI (#110)

Mukul bisht431878c0db90
diff --git a/pocket_tts/main.py b/pocket_tts/main.py
index f749b4b..0c03591 100644
--- a/pocket_tts/main.py
+++ b/pocket_tts/main.py
@@ -1,6 +1,7 @@
import io
import logging
import os
+import sys
import tempfile
import threading
from pathlib import Path
@@ -243,6 +244,13 @@ def generate(
log_level = logging.ERROR if quiet else logging.INFO
with enable_logging("pocket_tts", log_level):
+ if text == "-":
+ # Read text from stdin
+ text = sys.stdin.read()
+
+ if not text.strip():
+ logger.error("No input received from stdin.")
+ raise typer.Exit(code=1)
tts_model = TTSModel.load_model(
config, temperature, lsd_decode_steps, noise_clamp, eos_threshold
)