High-Quality Voice Cloning TTS for 600+ Languages
Python
Honor asr_model_name when the ASR model is loaded lazily (#221)
Chao Cao1574e06a7678
diff --git a/README.md b/README.mdindex 1f47371..b6f54e7 100644--- a/README.md+++ b/README.md@@ -162,7 +162,8 @@ audio = model.generate() # audio is a list of `np.ndarray` with shape (T,) at 24 kHz.# If you don't want to input `ref_text` manually, you can directly omit the `ref_text`.-# The model will use Whisper ASR to auto-transcribe it.+# The model will use Whisper ASR to auto-transcribe it. To use a local copy (or+# a different Whisper model), pass `asr_model_name="..."` to `from_pretrained`.sf.write("out.wav", audio[0], 24000)```diff --git a/omnivoice/models/omnivoice.py b/omnivoice/models/omnivoice.pyindex dcc0bb9..51dd8bd 100644--- a/omnivoice/models/omnivoice.py+++ b/omnivoice/models/omnivoice.py@@ -274,12 +274,13 @@ class OmniVoice(PreTrainedModel):self.duration_estimator = Noneself.sampling_rate = Noneself._asr_pipe = None+ self._asr_model_name = "openai/whisper-large-v3-turbo"@classmethoddef from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs):train_mode = kwargs.pop("train", False)load_asr = kwargs.pop("load_asr", False)- asr_model_name = kwargs.pop("asr_model_name", "openai/whisper-large-v3-turbo")+ asr_model_name = kwargs.pop("asr_model_name", None)# Suppress noisy INFO logs from transformers/huggingface_hub during loading_prev_disable = logging.root.manager.disable@@ -317,8 +318,10 @@ class OmniVoice(PreTrainedModel):model.duration_estimator = RuleDurationEstimator()+ if asr_model_name is not None:+ model._asr_model_name = asr_model_nameif load_asr:- model.load_asr_model(model_name=asr_model_name)+ model.load_asr_model()finally:logging.disable(_prev_disable)@@ -328,14 +331,20 @@ class OmniVoice(PreTrainedModel):# ASR support (optional, for auto-transcription)# -------------------------------------------------------------------- def load_asr_model(self, model_name: str = "openai/whisper-large-v3-turbo"):+ def load_asr_model(self, model_name: Optional[str] = None):"""Load a Whisper ASR model for reference audio transcription.Args:- model_name: HuggingFace model name or local path for the Whisper model.+ model_name: HuggingFace model name or local path for the Whisper+ model. Defaults to the ``asr_model_name`` passed to+ :meth:`from_pretrained` (``openai/whisper-large-v3-turbo``+ if unset)."""from transformers import pipeline as hf_pipeline+ if model_name is None:+ model_name = self._asr_model_name+logger.info("Loading ASR model %s ...", model_name)asr_dtype = (torch.float16