
    Oj                     X   S r SSKrSSKrSSKrSSKJr  SSKrSSKJr  SSKJ	r	  SSKJ
r  SSKJr  SS	KJr  SS
KJr  SSKJr  SSK	Jr  \R(                  r SSKJr  SSKJr  \R4                  " S5      r " S S5      r " S S\R:                  5      rg! \ a    SSKJr  SSKJr   NFf = f)z%[Experimental] Live Music API client.    N)AsyncIterator   )_api_module)_common)_live_converters)_transformers)errors)types)BaseApiClient)set_value_by_path)ClientConnection)connectzgoogle_genai.live_musicc                      \ rS rSrSrS\S\4S jrS\\	R                     SS4S	 jrS
\	R                  SS4S jrS\	R                  SS4S jrSS jrSS jrSS jrSS jrS\\	R*                     4S jrS\	R*                  4S jrSS jrSrg)AsyncMusicSession-   z![Experimental] AsyncMusicSession.
api_client	websocketc                     Xl         X l        g )N_api_client_ws)selfr   r   s      Y/var/www/html/leaf-doctor-v1/venv/lib/python3.13/site-packages/google/genai/live_music.py__init__AsyncMusicSession.__init__0   s    !H    promptsreturnNc           	      (  #    U R                   R                  (       a  [        S5      eSU Vs/ s H  n[        R                  " USS9PM     sn0nU R
                  R                  [        R                  " SU05      5      I S h  vN   g s  snf  N
7f)N4Live music generation is not supported in Vertex AI.weightedPromptsTconvert_keysclientContent	r   vertexaiNotImplementedErrorr   convert_to_dictr   sendjsondumps)r   r   promptclient_content_dicts       r   set_weighted_prompts&AsyncMusicSession.set_weighted_prompts4   s        
@ 
 ##& %%f4@# ((--

O5H#IJ
KKK Ls   ,BB8BBBconfigc                    #    U R                   R                  (       a  [        S5      e[        R                  " USS9nU R
                  R                  [        R                  " SU05      5      I S h  vN   g  N7f)Nr    Tr"   musicGenerationConfigr%   )r   r0   config_dicts      r   set_music_generation_config-AsyncMusicSession.set_music_generation_configE   s_        
@  ++FFk
((--

$;[#IJ
KKKs   A0A:2A83A:playback_controlc                    #    U R                   R                  (       a  [        S5      eSUR                  0nU R                  R                  [        R                  " U5      5      I S h  vN   g  N7f)Nr    playbackControl)r   r&   r'   valuer   r)   r*   r+   )r   r6   playback_control_dicts      r   _send_control_signal&AsyncMusicSession._send_control_signalP   sZ        
@   12B2H2HIHHMM$**%:;<<<s   A'A1)A/*A1c                 p   #    U R                  [        R                  R                  5      I Sh  vN $  N7f)z0Sends playback signal to start the music stream.N)r;   r
   LiveMusicPlaybackControlPLAYr   s    r   playAsyncMusicSession.play[   s(     **5+I+I+N+NOOOO   -646c                 p   #    U R                  [        R                  R                  5      I Sh  vN $  N7f)z2Sends a playback signal to pause the music stream.N)r;   r
   r>   PAUSEr@   s    r   pauseAsyncMusicSession.pause_   s(     **5+I+I+O+OPPPPrC   c                 p   #    U R                  [        R                  R                  5      I Sh  vN $  N7f)z{Sends a playback signal to stop the music stream.

Resets the music generation context while retaining the current config.
N)r;   r
   r>   STOPr@   s    r   stopAsyncMusicSession.stopc   s*     
 **5+I+I+N+NOOOOrC   c                 p   #    U R                  [        R                  R                  5      I Sh  vN $  N7f)zKReset the context (prompts retained) without stopping the music generation.N)r;   r
   r>   RESET_CONTEXTr@   s    r   reset_contextAsyncMusicSession.reset_contextj   s1     **&&44   rC   c                   #    U R                  5       I Sh  vN =n(       a'  U7v   U R                  5       I Sh  vN =n(       a  M&  gg N3 N7f)zVReceive model responses from the server.

Yields:
  The audio chunks from the server.
N)_receive)r   results     r   receiveAsyncMusicSession.receivep   s<      --/)
)&
)l --/)
)&
)
))s%   AA
#AAAAAc                   #    [         R                  " 5       n U R                  R                  SS9I S h  vN nW(       a   [         R"                  " U5      nO0 nU R*                  R,                  (       a  [/        S5      eUnU(       d7  U(       a0  [        R                  R                  UR                  S5      US 5        [         R                  R1                  XqR3                  5       S9$  N! [         a&    U R                  R                  5       I S h  vN  n N[
         a  nUR                  (       a-  UR                  R                  nUR                  R                  nO,Sn[        R                  R                  R                  US5      n[        R                  R                  XES 5         S nAGN|S nAff = f! [         R$                  R&                   a    [)        SU< 35      ef = f7f)	NFdecodei  zAbnormal closure.zFailed to parse response: r    code)responsekwargs)r
   LiveMusicServerMessager   recv	TypeErrorConnectionClosedrcvdrX   reason
websocketsframesCLOSE_CODE_EXPLANATIONSgetr	   APIErrorraise_errorr*   loadsdecoderJSONDecodeError
ValueErrorr   r&   r'   _from_response
model_dump)r   parameter_modelraw_responseerX   r`   rY   response_dicts           r   rQ   AsyncMusicSession._receivez   sz    224O688===66l H::l+ h   VWWmXoo!!(,,v"6$G''66'A'A'C 7  5 7 +88==?**l 6	
vv{{""::>>tEXYoo!!$556 \\)) H5l5EFGGHso   G/C. C,C. G/F> BG/,C. .'F;DF;G/	F;&B
F60G/6F;;G/>.G,,G/c                 T   #    U R                   R                  5       I Sh  vN   g N7f)z<Closes the bi-directional stream and terminates the session.N)r   closer@   s    r   rs   AsyncMusicSession.close   s     
((..
s   (&(r   )r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   listr
   WeightedPromptr.   LiveMusicGenerationConfigr4   r>   r;   rA   rF   rJ   rN   r   r[   rS   rQ   rs   __static_attributes__ r   r   r   r   -   s    ) ;K L%../LL"	L33	L	L	=#<<	=	=PQP]5+G+GH e:: Br   r   c                   x    \ rS rSrSr\R                  " S5      \R                  S\	S\
\   4S j5       5       rSrg)	AsyncLiveMusic   z[[Experimental] Live music module.

Live music can be accessed via `client.aio.live.music`.
zLRealtime music generation is experimental and may change in future versions.modelr   c               D  #    U R                   R                  5       n[        U[        5      (       a  UR	                  S5      n[
        R                  " U R                   U5      nU R                   R                  (       a  U R                   R                  R                  nU SU S3nU R                   R                  R                  nUb  UR                  5       O0 n[        R                  " [        R                  " [         R"                  " US9R%                  SS9S95      n['        US	S
/U5        [(        R*                  " U5      n	O[-        S5      e [/        XWS9 ISh  vN n
U
R1                  U	5      I Sh  vN   [2        R5                  U
R7                  SS9I Sh  vN 5        [9        U R                   U
S97v   SSS5      ISh  vN   g No NX N4 N! , ISh  vN  (       d  f       g= f! [:         a    [/        XWS9 ISh  vN  n
U
R1                  U	5      I Sh  vN    [2        R5                  U
R7                  5       I Sh  vN  5        [9        U R                   U
S97v   SSS5      ISh  vN     g! , ISh  vN  (       d  f        g= ff = f7f)z0[Experimental] Connect to the live music server.zutf-8z!/ws/google.ai.generativelanguage.z$.GenerativeService.BidiGenerateMusicN)r   T)exclude_none)from_objectsetupr   r    )additional_headersFrV   )r   r   )extra_headers)r   _websocket_base_url
isinstancebytesrW   tt_modelapi_key_http_optionsapi_versionheaderscopyr   r(   live_converters$_LiveMusicConnectParameters_to_mldevr
   LiveMusicConnectParametersrl   setvr*   r+   r'   r   r)   loggerinfor\   r   r]   )r   r   base_urltransformed_modelversionurioriginal_headersr   request_dictrequestwss              r   r   AsyncLiveMusic.connect   s      335H(E"")h		$"2"2E:  ..::gj9'Bfgc))77??+;+G %%'Rg ,,

>
>::'

-l <'7+->?

<(g VWWK99Rggg"'''//04+;+;rJJ	 :99/ :999
  K44ggg"'')OO$4+;+;rJJ	 544444Ks   EJ G4 "G#G4 &G;G<%G!G
"GG4 GG4 J G4 GGG4 G1 G#!G1-G4 0J 1G4 4JHJJ%H(&'JI J.J9I<:J?J J	J
J	JJ JJ r~   N)ru   rv   rw   rx   ry   r   experimental_warning
contextlibasynccontextmanagerstrr   r   r   r}   r~   r   r   r   r      sQ    
 T !!(KC (KM:K,L (K "(Kr   r   )ry   r   r*   loggingtypingr   ra    r   r   r   r   r   r   r	   r
   r   r   r   r   r^   websockets.asyncio.clientr   r   ModuleNotFoundErrorwebsockets.client	getLoggerr   r   
BaseModuler   r~   r   r   <module>r      s     ,         1     & ... (8/
 
		4	5p pf2K[++ 2Ku  (0'(s   B B)(B)