teddybear082 commited on
Commit
7eb9ff9
·
1 Parent(s): 47a0ea8

Support bundled model

Browse files

-Support bundled model (beta, until devs change underlying repo)

-add additional voices tts voices

Files changed (1) hide show
  1. pocket_tts_openai_server.py +11 -13
pocket_tts_openai_server.py CHANGED
@@ -49,10 +49,12 @@ if getattr(sys, 'frozen', False):
49
  # Default Voices Dir when frozen (bundled)
50
  # We will assume 'voices' is bundled into the root of the executable
51
  BUNDLE_VOICES_DIR = os.path.join(base_path, 'voices')
 
52
  else:
53
  app = Flask(__name__)
54
  base_path = os.path.dirname(os.path.abspath(__file__))
55
  BUNDLE_VOICES_DIR = None
 
56
 
57
  # --- Helpers ---
58
  def get_voice_state(voice_id_or_path):
@@ -273,19 +275,15 @@ def main():
273
  model = TTSModel.load_model(variant=args.model_path)
274
  elif getattr(sys, 'frozen', False):
275
  # Check if model is bundled in 'model' dir
276
- #bundled_model_dir = os.path.join(base_path, 'model')
277
- #if os.path.isdir(bundled_model_dir):
278
- #logger.info(f"Using bundled model from: {bundled_model_dir}")
279
- # We assume the directory contains the necessary files and pass the directory path
280
- # Depending on pocket-tts implementation, passing the dir might work if it looks for files inside
281
- # However, load_model usually takes a variant name or a path to a specific file/dir?
282
- # Let's assume passing the directory works if it contains the artifacts.
283
- # Actually, looking at pocket-tts, usually one passes the safelytensors file or just the variant name.
284
- # If we bundle it, we should find the .safetensors file?
285
- # Usually load_model(variant=path) works.
286
- #model = TTSModel.load_model(variant=bundled_model_dir)
287
- #else:
288
- model = TTSModel.load_model()
289
  else:
290
  model = TTSModel.load_model()
291
 
 
49
  # Default Voices Dir when frozen (bundled)
50
  # We will assume 'voices' is bundled into the root of the executable
51
  BUNDLE_VOICES_DIR = os.path.join(base_path, 'voices')
52
+ BUNDLE_MODEL_PATH = os.path.join(base_path, 'model', 'b6369a24.yaml')
53
  else:
54
  app = Flask(__name__)
55
  base_path = os.path.dirname(os.path.abspath(__file__))
56
  BUNDLE_VOICES_DIR = None
57
+ BUNDLE_MODEL_PATH = None
58
 
59
  # --- Helpers ---
60
  def get_voice_state(voice_id_or_path):
 
275
  model = TTSModel.load_model(variant=args.model_path)
276
  elif getattr(sys, 'frozen', False):
277
  # Check if model is bundled in 'model' dir
278
+ if os.path.isfile(BUNDLE_MODEL_PATH):
279
+ logger.info(f"Using bundled model from: {BUNDLE_MODEL_PATH}")
280
+ try:
281
+ model = TTSModel.load_model(variant=BUNDLE_MODEL_PATH)
282
+ except Exception as e:
283
+ logging.error(f"Error trying to load models bundled with .exe: {e}. Returning to default model load.")
284
+ model = TTSModel.load_model()
285
+ else:
286
+ model = TTSModel.load_model()
 
 
 
 
287
  else:
288
  model = TTSModel.load_model()
289