High-Quality Voice Cloning TTS for 600+ Languages
Python
Expose pad_duration and fade_duration to let users control fade-in/out and silence padding
Han Zhu398b61135c8d
diff --git a/docs/generation-parameters.md b/docs/generation-parameters.mdindex 6ff0a22..8deb7fd 100644--- a/docs/generation-parameters.md+++ b/docs/generation-parameters.md@@ -57,6 +57,8 @@ Priority: `duration` > `speed`.|---|---|---|---|| `preprocess_prompt` | bool | True | Whether to apply preprocessing to the voice-clone prompt audio (remove long silences in reference audio, add punctuation in the end of reference text). || `postprocess_output` | bool | True | Apply post-processing to generated audio (remove long silences). |+| `pad_duration` | float | 0.1 | Silence padding duration per side in seconds. Set to 0 to disable. |+| `fade_duration` | float | 0.1 | Fade-in/out curve duration in seconds. Set to 0 to disable. |## Long-Form Generationdiff --git a/omnivoice/models/omnivoice.py b/omnivoice/models/omnivoice.pyindex 4d78f8a..d36dec0 100644--- a/omnivoice/models/omnivoice.py+++ b/omnivoice/models/omnivoice.py@@ -107,6 +107,8 @@ class OmniVoiceGenerationConfig:postprocess_output: bool = Trueaudio_chunk_duration: float = 15.0audio_chunk_threshold: float = 30.0+ pad_duration: float = 0.1+ fade_duration: float = 0.1@classmethoddef from_dict(cls, kwargs_dict):@@ -539,6 +541,10 @@ class OmniVoice(PreTrainedModel):this duration (seconds) and generate chunk by chunk.audio_chunk_threshold: Only apply chunking if estimated audioduration exceeds this threshold (seconds).+ pad_duration: Silence padding duration per side in seconds+ (0 to disable).+ fade_duration: Fade-in/out curve duration in seconds+ (0 to disable).Returns:``audios`` a list of 1-D ``np.ndarray`` with shape ``(T,)`` andsampling rate consistent with the model's audio tokenizer@@ -742,27 +748,27 @@ class OmniVoice(PreTrainedModel):audio_waveform = self._post_process_audio(audio_waveform,- postprocess_output=gen_config.postprocess_output,ref_rms=rms,+ gen_config=gen_config,)return audio_waveform.squeeze(0)def _post_process_audio(self,generated_audio: np.ndarray,- postprocess_output: bool,ref_rms: Union[float, None],+ gen_config: OmniVoiceGenerationConfig,) -> np.ndarray:"""Optionally remove long silences, adjust volume, and add edge padding.Args:generated_audio: Numpy array of shape (1, T).- postprocess_output: If True, remove long silences and apply fade/pad.ref_rms: RMS of the reference audio for volume normalisation.+ gen_config: Generation config controlling post-processing behaviour.Returns:Processed numpy array of shape (1, T)."""- if postprocess_output:+ if gen_config.postprocess_output:generated_audio = remove_silence(generated_audio,self.sampling_rate,@@ -780,6 +786,8 @@ class OmniVoice(PreTrainedModel):generated_audio = fade_and_pad_audio(generated_audio,+ pad_duration=gen_config.pad_duration,+ fade_duration=gen_config.fade_duration,sample_rate=self.sampling_rate,)return generated_audio