
    i                         S r SSKrSSKrSSKrSSKrSSKJr  SSKJ	r	  S r
S\R                  4S jrS r\S	:X  a  \" 5         gg)
a  Single-item inference CLI for OmniVoice.

Generates audio from a single text input using voice cloning,
voice design, or auto voice.

Usage:
    # Voice cloning
    omnivoice-infer --model k2-fsa/OmniVoice         --text "Hello, this is a text for text-to-speech."         --ref_audio ref.wav --ref_text "Reference transcript." --output out.wav

    # Voice design
    omnivoice-infer --model k2-fsa/OmniVoice         --text "Hello, this is a text for text-to-speech."         --instruct "male, British accent" --output out.wav

    # Auto voice
    omnivoice-infer --model k2-fsa/OmniVoice         --text "Hello, this is a text for text-to-speech." --output out.wav
    N)	OmniVoice)str2boolc                      [         R                  R                  5       (       a  g[         R                  R                  R                  5       (       a  gg)z8Auto-detect the best available device: CUDA > MPS > CPU.cudampscpu)torchr   is_availablebackendsr        //mnt/workspace/OmniVoice/omnivoice/cli/infer.pyget_best_devicer   !   s7    zz  ~~&&((r   returnc                  R   [         R                  " S[         R                  S9n U R                  S[        SSS9  U R                  S[        SS	S
9  U R                  S[        SSS
9  U R                  S[        S SS9  U R                  S[        S SS9  U R                  S[        S SS9  U R                  S[        S SS9  U R                  S[
        SS9  U R                  S[        SS9  U R                  S[        SS9  U R                  S[        S SS9  U R                  S[        SS9  U R                  S [        SS9  U R                  S![        SS9  U R                  S"[        S#S9  U R                  S$[        S#S9  U R                  S%[        S&S9  U R                  S'[        S S(S9  U $ ))NzOmniVoice single-item inference)descriptionformatter_classz--modelzk2-fsa/OmniVoicez-Model checkpoint path or HuggingFace repo id.)typedefaulthelpz--textTzText to synthesize.)r   requiredr   z--outputzOutput WAV file path.z--ref_audioz,Reference audio file path for voice cloning.z
--ref_textz.Reference text describing the reference audio.z
--instructz(Style instruction for voice design mode.z
--languagez3Language name (e.g. 'English') or code (e.g. 'en').z
--num_step    )r   r   z--guidance_scaleg       @z--speedg      ?z
--durationzFixed output duration in seconds. If set, overrides the model's duration estimation. The speed factor is automatically adjusted to match while preserving language-aware pacing.z	--t_shiftg?z	--denoisez--postprocess_outputz--layer_penalty_factorg      @z--position_temperaturez--class_temperatureg        z--devicez<Device to use for inference. Auto-detected if not specified.)argparseArgumentParserArgumentDefaultsHelpFormatteradd_argumentstrintfloatr   )parsers    r   
get_parserr!   *   s   $$5 >>F "<	   "	   $	   ;	   =	   7	   B	   3;
*D
	s;
D	   %=
(DA
  
 0ucJ
0ucJ
-E3G
K	   Mr   c                     Sn [         R                  " U [         R                  SS9  [        5       R	                  5       nUR
                  =(       d
    [        5       n[         R                  " SUR                   SU S35        [        R                  " UR                  U[        R                  S9n[         R                  " SUR                  S S	  S
35        UR                  UR                  UR                  UR                   UR"                  UR$                  UR&                  UR(                  UR*                  UR,                  UR.                  UR0                  UR2                  UR4                  UR6                  UR8                  S9n[:        R<                  " UR>                  US   UR@                  5        [         R                  " SUR>                   35        g )Nz?%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)sT)formatlevelforcezLoading model from z on z ...)
device_mapdtypezGenerating audio for: P   z...)textlanguage	ref_audioref_textinstructdurationnum_stepguidance_scalespeedt_shiftdenoisepostprocess_outputlayer_penalty_factorposition_temperatureclass_temperaturer   z	Saved to )!loggingbasicConfigINFOr!   
parse_argsdevicer   infomodelr   from_pretrainedr	   float16r)   generater*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   sfwriteoutputsampling_rate)	formatterargsr<   r>   audioss        r   mainrI   z   s]   QIyDI<""$D[[-O-FLL&tzzl$vhdCD%%

vU]]E LL)$))CR.)9=>^^YY..**jj22!66!6600  F$ HHT[[&)U%8%89LL9T[[M*+r   __main__)__doc__r   r8   r	   	soundfilerB   omnivoice.models.omnivoicer   omnivoice.utils.commonr   r   r   r!   rI   __name__r   r   r   <module>rP      sR   *     0 +MH++ M` ,F zF r   