Add cpu inference option

This commit is contained in:
Sematre 2025-07-05 20:43:57 +02:00
parent bfc200f6ee
commit 76f14ddfb0
No known key found for this signature in database
2 changed files with 18 additions and 1 deletions

View File

@ -234,6 +234,9 @@ echo "Hey, how are you?" | python scripts/tts_pytorch.py - -
# From text file to audio file # From text file to audio file
python scripts/tts_pytorch.py text_to_say.txt audio_output.wav python scripts/tts_pytorch.py text_to_say.txt audio_output.wav
# Use --cpu flag for CPU-only inference
python scripts/tts_pytorch.py --cpu text_to_say.txt audio_output.wav
``` ```
This requires the [moshi package](https://pypi.org/project/moshi/), which can be installed via pip. This requires the [moshi package](https://pypi.org/project/moshi/), which can be installed via pip.

View File

@ -44,12 +44,26 @@ def main():
help="The voice to use, relative to the voice repo root. " help="The voice to use, relative to the voice repo root. "
f"See {DEFAULT_DSM_TTS_VOICE_REPO}", f"See {DEFAULT_DSM_TTS_VOICE_REPO}",
) )
parser.add_argument(
"--cpu",
action="store_true",
help="Use CPU instead of GPU for inference",
)
args = parser.parse_args() args = parser.parse_args()
print("Loading model...") print("Loading model...")
checkpoint_info = CheckpointInfo.from_hf_repo(args.hf_repo) checkpoint_info = CheckpointInfo.from_hf_repo(args.hf_repo)
# Set device and precision
if args.cpu:
device = torch.device("cpu")
dtype = torch.float32
else:
device = torch.device("cuda")
dtype = torch.bfloat16
tts_model = TTSModel.from_checkpoint_info( tts_model = TTSModel.from_checkpoint_info(
checkpoint_info, n_q=32, temp=0.6, device=torch.device("cuda") checkpoint_info, n_q=32, temp=0.6, device=device, dtype=dtype
) )
if args.inp == "-": if args.inp == "-":