
    wi                     $   d Z ddlZddlZddlZddlZddlZddlZddl	m
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZmZmZmZ dde
ee                  d	ej        fd
Zdde
ee                  d	efdZedk    r ej         e                       dS dS )z0
Command line interface for Perth watermarking.
    N)OptionalList)PerthImplicitWatermarker)DummyWatermarker)
get_config)
load_audio
save_audiocalculate_audio_metricsplot_audio_comparisonargsreturnc                    t          j        dt           j                  }|                    dd           |                    ddd           |                    d	d
ddgd           |                    dddd           |                    ddddgd           |                    ddd           |                    dddd           |                    |           S )zParse command line arguments.zPerth - Audio Watermarking Tool)descriptionformatter_class
input_filezPath to the input audio file)helpz--outputz-ozmPath to save the output watermarked audio file. If not provided, appends '_watermarked' to the input filenamez--methodz-mperthdummyzWatermarking method to use)choicesr   z	--extractz-e
store_truezEExtract watermark from the input file instead of applying a watermark)actionr   z--devicez-dcpucudaz+Device to use for neural network processingz--configz-czPath to a configuration filez--visualizez-vzEGenerate visualization of watermark effect (only when not extracting))argparseArgumentParserArgumentDefaultsHelpFormatteradd_argument
parse_args)r   parsers     g/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/perth/cli/watermark_cli.pyr   r      sN   $5 >  F
 +IJJJ

D]  ^ ^ ^ 
D7G2D9  ; ; ;
T,d  f f f

D5&/J  L L L

D;  = = =
tLd  f f f T"""    c                    t          |           }t          |j                  }|j        r|                    dd|j                   |j        r|                    dd|j                   |                    dd          }|                    dd          }	 t          d|j                    t          |j                  \  }}|dk    rRt          d| d           |                    dd          }|                    dd	          }t          |||
          }	nt          d           t                      }	|j        r_t          d           |	                    ||          }
t          d|
            t          dt          j        |
          d           dS t          d           |                                }|	                    |d|          }|j        r|j        }n.t&          j                            |j                  \  }}| d| }t-          |||           t          d|            t          d           |	                    ||          }t          dt          j        |          d           t/          ||          }t          d           t          d|d         dd           t          d|d         d            t          d!|d"         dd           |j        rLt&          j                            |          d         d#z   }t          d$|            t3          ||||           dS # t4          $ r)}t          d%| t6          j        &           Y d}~d'S d}~ww xY w)(z'Main function for the watermarking CLI.generaldefault_watermarkerr   devicezLoading audio file: z(Initializing Perth watermarker (device: z)...
models_dirrun_name)r'   r&   r%   z!Initializing dummy watermarker...zExtracting watermark...)sample_ratezExtracted watermark: zWatermark confidence: z.4fr   zApplying watermark...N)	watermarkr(   _watermarkedzWatermarked audio saved to: zVerifying watermark...z#Watermark verification confidence: z
Audio Quality Metrics:z  Signal-to-Noise Ratio (SNR): snrz.2fz dBz  Mean Squared Error (MSE): msez.8fz%  Peak Signal-to-Noise Ratio (PSNR): psnrz_comparison.pngz
Generating visualization to: zError: )file   )r   r   configmethodsetr%   getprintr   r   r   r   extractget_watermarknpmeancopyapply_watermarkoutputospathsplitextr	   r
   	visualizer   	Exceptionsysstderr)r   parsed_argsr0   r1   r%   wavsrr&   r'   watermarkerr)   original_audiowatermarked_audiooutput_pathbaseext	extractedmetricsviz_pathes                       r    mainrP   ,   s   T""K *++F  I

93[5GHHH :

7Hk&8999ZZ	#899FZZ**F@=[%;==>>>[344R WIVIIIJJJG\::Jzz':66H2!%  KK 5666*,,K )	+,,,#11#21FFI5)55666C279+=+=CCCDDD1 )*** XXZZN + ; ;C4]_ ; ` ` ! 9)0G,,[-CDD	c!%88388(+r:::>>>??? *+++#112CQS1TTIP	8J8JPPPQQQ .n>OPPG,---KGENKKKKLLLEEEEFFFR'&/RRRRSSS $ W7++K88;>OOBBBCCC%n6GXVVV1   mmm#*----qqqqqs    DM  F%M 
M:M55M:__main__)N)__doc__r   r<   rA   numpyr7   librosa	soundfilesftypingr   r   4perth.perth_net.perth_net_implicit.perth_watermarkerr   perth.dummy_watermarkerr   perth.configr   perth.utilsr   r	   r
   r   str	Namespacer   intrP   __name__exit r!   r    <module>rb      s]     				 



          ! ! ! ! ! ! ! ! Y Y Y Y Y Y 4 4 4 4 4 4 # # # # # # ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^# #Xd3i( #H4F # # # #2P PxS	" Pc P P P Pf zCHTTVV r!   