
                            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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.    )absolute_import)division)unicode_literals)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.ArgsI   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.MakeRequestU   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>o   s    Ar$   z<Waiting for [{}] to complete. This may take several minutes.)wait_ceiling_ms)r   GetClientInstancer
   
SPEECH_APIr   r3   MESSAGES_MODULE_requestspeechLongrunningrecognizeasync_r   WaitForCloudOperationPollerNoResources
operationsnameformatOPERATION_TIMEOUT_MS)r/   r0   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 r7   )r
   MaybePrintSttUiLinkr@   )r/   unused_resources_were_displayeds     r!   EpilogRecognizeLongRunningGA.Epilogu   s    T]]+r$   )r@   N)__name__
__module____qualname____firstlineno____doc__detailed_helpr   r	   RecognizeArgsToRequestMapperr   classmethodr"   r3   rL   rQ   __static_attributes__r8   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$ )RecognizeLongRunningBetay   	v1p1beta1c                 j   > [         [        [        ]  U5        U R                  R	                  U5        g r7   )superr]   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$ r7   )ra   r]   r3   r   !UpdateBetaArgsInRecognitionConfigr'   r/   r0   r1   r2   rd   s       r!   r3   $RecognizeLongRunningBeta.MakeRequest   s2    ,d?OG77nnMNr$   r8   )rS   rT   rU   rV   r   rW   rX   copyr   rZ   r"   r3   r[   __classcell__rd   s   @r!   r]   r]   y   sC    "**'(66;;=-+: : r$   r]   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 r7   )ra   rn   r"   r   AddAlphaRecognizeArgsToParserr   rc   s     r!   r"   RecognizeLongRunningAlpha.Args   s,    	
#%>DVL226??Kr$   c                 x   > [         [        U ]  X5      nU R                  R	                  XR
                  5        U$ r7   )ra   rn   r3   r   "UpdateAlphaArgsInRecognitionConfigr'   rh   s       r!   r3   %RecognizeLongRunningAlpha.MakeRequest   s2    -t@PG88~~NNr$   r8   )rS   rT   rU   rV   r]   rW   r   rZ   r"   r3   r[   rk   rl   s   @r!   rn   rn      s1    $,,'+L L r$   rn   N)rW   
__future__r   r   r   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper   $googlecloudsdk.command_lib.ml.speechr	   r
   rI   ReleaseTracksReleaseTrackGACommandr   BETAr]   rX   ALPHArn   r8   r$   r!   <module>r      s    * &  ' , . ( 6 5
 +  D%%(()T,T\\ T, *T,n D%%**+5  ,$;  & & 7 D%%++, 8  -r$   