
    |                        S 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r	\R                  " \R                  R                  5       " S S	\R                  5      5       r\R                  " \R                  R                  5       " S
 S\5      5       rS\R"                  S'   \R                  " \R                  R$                  5       " S S\5      5       rg)z#Recognize speech in provided audio.    )apis)waiter)base)flags)utili \&c                   l    \ rS rSrSrSSSS.rSr\R                  " 5       r	\
S 5       rS	 rS
 rS rSrg)RecognizeLongRunningGA   z3Get transcripts of longer audio from an audio file.zGet a transcript of audio up to 80 minutes in length. If the audio is
under 60 seconds, you may also use `{parent_command} recognize` to
analyze it.
a8  To block the command from completing until analysis is finished, run:

  $ {command} AUDIO_FILE --language-code=LANGUAGE_CODE --sample-rate=SAMPLE_RATE

You can also receive an operation as the result of the command by running:

  $ {command} AUDIO_FILE --language-code=LANGUAGE_CODE --sample-rate=SAMPLE_RATE --async

This will return information about an operation. To get information about the
operation, run:

  $ {parent_command} operations describe OPERATION_ID

To poll the operation until it's complete, run:

  $ {parent_command} operations wait OPERATION_ID
zThis command uses the speech/v1 API. The full documentation for this API
can be found at: https://cloud.google.com/speech-to-text/docs/quickstart-protocol
)DESCRIPTIONEXAMPLESAPI REFERENCEv1c                     UR                   R                  S5        U R                  R                  XR                  5        [
        R                  R                  U5        UR                  S[        R                  SS9  g )Njsonz--output-urizTLocation to which the results should be written. Must be a Google Cloud Storage URI.)typehelp)display_info	AddFormatflags_mapperAddRecognizeArgsToParserAPI_VERSIONr   
ASYNC_FLAGAddToParseradd_argumentr   ValidateOutputUri)clsparsers     /lib/surface/ml/speech/recognize_long_running.pyArgsRecognizeLongRunningGA.ArgsF   sd    
!!&)--fooFOO'
##$  %    c                     UR                  [        R                  " UR                  U R                  5      U R
                  R                  X5      S9nUR                  b  UR                  UR                  S9Ul	        U$ )N)audioconfig)gcsUri)
LongRunningRecognizeRequestr   GetRecognitionAudioFromPathr#   r   r   MakeRecognitionConfig
output_uriTranscriptOutputConfigoutputConfig)selfargsmessagesrequests       r   MakeRequest"RecognizeLongRunningGA.MakeRequestR   sv    22..tzz4;K;KL  66tF 3 HG "%<< = "gNr!   c                    [         R                  " [        R                  U R                  5      nU R                  XR                  5      U l        UR                  R                  U R                  5      nUR                  (       a  U$ [        R                  " [        R                  " UR                  S 5      UR                  SR!                  UR                  5      ["        S9$ )zRun 'ml speech recognize'.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Nothing.
c                     U $ N )xs    r   <lambda>,RecognizeLongRunningGA.Run.<locals>.<lambda>l   s    Ar!   z<Waiting for [{}] to complete. This may take several minutes.)wait_ceiling_ms)r   GetClientInstancer   
SPEECH_APIr   r0   MESSAGES_MODULE_requestspeechLongrunningrecognizeasync_r   WaitForCloudOperationPollerNoResources
operationsnameformatOPERATION_TIMEOUT_MS)r,   r-   client	operations       r   RunRecognizeLongRunningGA.Run[   s     ##DOOT5E5EFF$$T+A+ABDM224==AI{{>>..v/@/@+NFMMNN	,. .r!   c                 D    [         R                  " U R                  5        g r4   )r   MaybePrintSttUiLinkr=   )r,   unused_resources_were_displayeds     r   EpilogRecognizeLongRunningGA.Epilogr   s    T]]+r!   )r=   N)__name__
__module____qualname____firstlineno____doc__detailed_helpr   r   RecognizeArgsToRequestMapperr   classmethodr   r0   rI   rN   __static_attributes__r5   r!   r   r	   r	      sR    ;&7-B +335,	% 	%..,r!   r	   c                      ^  \ rS rSr\R
                  r\R                  R                  5       rSr\	U 4S j5       r
U 4S jrSrU =r$ )RecognizeLongRunningBetav   	v1p1beta1c                 j   > [         [        [        ]  U5        U R                  R	                  U5        g r4   )superrZ   r   r   AddBetaRecognizeArgsToParserr   r   	__class__s     r   r   RecognizeLongRunningBeta.Args~   s(    	
"$<B6J11&9r!   c                 x   > [         [        U ]  X5      nU R                  R	                  XR
                  5        U$ r4   )r^   rZ   r0   r   !UpdateBetaArgsInRecognitionConfigr$   r,   r-   r.   r/   ra   s       r   r0   $RecognizeLongRunningBeta.MakeRequest   s2    ,d?OG77nnMNr!   r5   )rP   rQ   rR   rS   r	   rT   rU   copyr   rW   r   r0   rX   __classcell__ra   s   @r   rZ   rZ   v   sC    "**'(66;;=-+: : r!   rZ   zThis command uses the speech/v1p1beta1 API. The full documentation for this API
can be found at: https://cloud.google.com/speech-to-text/docs/quickstart-protocol
r   c                   Z   ^  \ rS rSr\R
                  rSr\U 4S j5       rU 4S jr	Sr
U =r$ )RecognizeLongRunningAlpha   r\   c                 ~   > [         [        [        ]  U5        U R                  R	                  XR
                  5        g r4   )r^   rk   r   r   AddAlphaRecognizeArgsToParserr   r`   s     r   r   RecognizeLongRunningAlpha.Args   s,    	
#%>DVL226??Kr!   c                 x   > [         [        U ]  X5      nU R                  R	                  XR
                  5        U$ r4   )r^   rk   r0   r   "UpdateAlphaArgsInRecognitionConfigr$   re   s       r   r0   %RecognizeLongRunningAlpha.MakeRequest   s2    -t@PG88~~NNr!   r5   )rP   rQ   rR   rS   rZ   rT   r   rW   r   r0   rX   rh   ri   s   @r   rk   rk      s1    $,,'+L L r!   rk   N)rT   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper   $googlecloudsdk.command_lib.ml.speechr   r   rF   ReleaseTracksReleaseTrackGACommandr	   BETArZ   rU   ALPHArk   r5   r!   r   <module>r|      s    * - . ( 6 5
 +  D%%(()T,T\\ T, *T,n D%%**+5  ,$;  & & 7 D%%++, 8  -r!   