mirror of
https://github.com/PierrunoYT/Kokoro-TTS-Local.git
synced 2025-01-27 02:30:25 +03:00
Add voice listing functionality
- Add list_available_voices() function to models.py - Add --list-voices argument to tts_demo.py - Enable users to view all available voice options
This commit is contained in:
17
models.py
17
models.py
@@ -1,7 +1,7 @@
|
||||
import torch
|
||||
import os
|
||||
import sys
|
||||
from huggingface_hub import hf_hub_download
|
||||
from huggingface_hub import hf_hub_download, list_repo_files
|
||||
import espeakng_loader
|
||||
from phonemizer.backend.espeak.wrapper import EspeakWrapper
|
||||
from importlib.util import spec_from_file_location, module_from_spec
|
||||
@@ -92,4 +92,17 @@ def generate_speech(model, text, voice=None, lang='a', device='cpu'):
|
||||
print(f"Error generating speech: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return None, None
|
||||
return None, None
|
||||
|
||||
def list_available_voices():
|
||||
"""List all available voices from the official voicepacks."""
|
||||
try:
|
||||
repo_id = "hexgrad/Kokoro-82M"
|
||||
files = list_repo_files(repo_id)
|
||||
# Filter for voice files in the voices directory and remove .pt extension
|
||||
voices = [f.replace('voices/', '').replace('.pt', '')
|
||||
for f in files if f.startswith('voices/') and f.endswith('.pt')]
|
||||
return sorted(voices)
|
||||
except Exception as e:
|
||||
print(f"Error listing voices: {e}")
|
||||
return []
|
||||
10
tts_demo.py
10
tts_demo.py
@@ -1,5 +1,5 @@
|
||||
import torch
|
||||
from models import build_model, load_voice, generate_speech
|
||||
from models import build_model, load_voice, generate_speech, list_available_voices
|
||||
import argparse
|
||||
|
||||
def main():
|
||||
@@ -8,8 +8,16 @@ def main():
|
||||
parser = argparse.ArgumentParser(description='Kokoro TTS Demo')
|
||||
parser.add_argument('--text', type=str, help='Text to synthesize (optional)')
|
||||
parser.add_argument('--voice', type=str, default='af', help='Voice to use (default: af)')
|
||||
parser.add_argument('--list-voices', action='store_true', help='List all available voices')
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.list_voices:
|
||||
voices = list_available_voices()
|
||||
print("\nAvailable voices:")
|
||||
for voice in voices:
|
||||
print(f"- {voice}")
|
||||
return
|
||||
|
||||
# Set up device
|
||||
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
||||
print(f"Using device: {device}")
|
||||
|
||||
Reference in New Issue
Block a user