(self, request, context)
| 473 | return self._voice_cache[voice_path] |
| 474 | |
| 475 | def TTS(self, request, context): |
| 476 | try: |
| 477 | # Get voice selection |
| 478 | # Priority: request.voice > AudioPath > default |
| 479 | voice_path = None |
| 480 | voice_key = None |
| 481 | |
| 482 | if request.voice: |
| 483 | # Try to get voice by name |
| 484 | voice_path = self._get_voice_path(request.voice) |
| 485 | if voice_path: |
| 486 | voice_key = request.voice |
| 487 | elif self.audio_path: |
| 488 | # Use AudioPath from LoadModel as voice file |
| 489 | if os.path.isabs(self.audio_path): |
| 490 | voice_path = self.audio_path |
| 491 | elif self.model_file: |
| 492 | model_file_base = os.path.dirname(self.model_file) |
| 493 | voice_path = os.path.join(model_file_base, self.audio_path) |
| 494 | elif self.model_path: |
| 495 | voice_path = os.path.join(self.model_path, self.audio_path) |
| 496 | else: |
| 497 | voice_path = self.audio_path |
| 498 | elif self.default_voice_key: |
| 499 | voice_path = self._get_voice_path(self.default_voice_key) |
| 500 | voice_key = self.default_voice_key |
| 501 | |
| 502 | if not voice_path or not os.path.exists(voice_path): |
| 503 | return backend_pb2.Result( |
| 504 | success=False, |
| 505 | message=f"Voice file not found: {voice_path}. Please provide a valid voice preset or AudioPath." |
| 506 | ) |
| 507 | |
| 508 | # Load voice preset |
| 509 | prefilled_outputs = self._ensure_voice_cached(voice_path) |
| 510 | if prefilled_outputs is None: |
| 511 | return backend_pb2.Result( |
| 512 | success=False, |
| 513 | message=f"Failed to load voice preset from {voice_path}" |
| 514 | ) |
| 515 | |
| 516 | # Get generation parameters from options |
| 517 | cfg_scale = self.options.get("cfg_scale", self.cfg_scale) |
| 518 | inference_steps = self.options.get("inference_steps", self.inference_steps) |
| 519 | do_sample = self.options.get("do_sample", False) |
| 520 | temperature = self.options.get("temperature", 0.9) |
| 521 | top_p = self.options.get("top_p", 0.9) |
| 522 | |
| 523 | # Update inference steps if needed |
| 524 | if inference_steps != self.inference_steps: |
| 525 | self.model.set_ddpm_inference_steps(num_steps=inference_steps) |
| 526 | self.inference_steps = inference_steps |
| 527 | |
| 528 | # Prepare text |
| 529 | text = request.text.strip().replace("'", "'").replace('"', '"').replace('"', '"') |
| 530 | |
| 531 | # Prepare inputs |
| 532 | inputs = self.processor.process_input_with_cached_prompt( |
nothing calls this directly
no test coverage detected