
                            d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	l
mZ d
Z e	j                  e	j                  j                          G d de	j"                               Z e	j                  e	j                  j&                         G d de             Zdej*                  d<    e	j                  e	j                  j,                         G d de             Zy)z#Recognize speech in provided audio.    )absolute_import)division)unicode_literals)apis)waiter)base)flags)utili \&c                   d    e Zd ZdZddddZdZ ej                         Ze	d        Z
d Zd	 Zd
 Zy)RecognizeLongRunningGAz3Get 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                    |j                   j                  d       | j                  j                  || j                         t
        j                  j                  |       |j                  dt        j                  d       y )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ArgszRecognizeLongRunningGA.ArgsI   sf    
!!&)--fcooFOO'
##$  %    c                 
   |j                  t        j                  |j                  | j                        | j
                  j                  ||            }|j                  !|j                  |j                        |_	        |S )N)audioconfig)gcsUri)
LongRunningRecognizeRequestr
   GetRecognitionAudioFromPathr$   r   r   MakeRecognitionConfig
output_uriTranscriptOutputConfigoutputConfig)selfargsmessagesrequests       r    MakeRequestz"RecognizeLongRunningGA.MakeRequestU   sx    22..tzz4;K;KL  66tXF 3 HG "%<< = "gNr"   c                    t        j                  t        j                  | j                        }| j                  ||j                        | _        |j                  j                  | j                        }|j                  r|S t        j                  t        j                  |j                  d       |j                  dj!                  |j                        t"              S )zRun 'ml speech recognize'.

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

    Returns:
      Nothing.
    c                     | S N )xs    r    <lambda>z,RecognizeLongRunningGA.Run.<locals>.<lambda>o   s    Ar"   z<Waiting for [{}] to complete. This may take several minutes.)wait_ceiling_ms)r   GetClientInstancer
   
SPEECH_APIr   r1   MESSAGES_MODULE_requestspeechLongrunningrecognizeasync_r   WaitForCloudOperationPollerNoResources
operationsnameformatOPERATION_TIMEOUT_MS)r-   r.   client	operations       r    RunzRecognizeLongRunningGA.Run^   s     ##DOOT5E5EFF$$T6+A+ABDM224==AI{{>>..v/@/@+NFMMNN	,. .r"   c                 B    t        j                  | j                         y r4   )r
   MaybePrintSttUiLinkr<   )r-   unused_resources_were_displayeds     r    EpilogzRecognizeLongRunningGA.Epilogu   s    T]]+r"   N)__name__
__module____qualname____doc__detailed_helpr   r	   RecognizeArgsToRequestMapperr   classmethodr!   r1   rH   rL   r5   r"   r    r   r   !   sT    ;&7-B +3335,	% 	%..,r"   r   c                        e Zd Zej                  Zej
                  j                         ZdZe fd       Z	 fdZ
 xZS )RecognizeLongRunningBeta	v1p1beta1c                 j    t         t        t          |       | j                  j	                  |       y r4   )superrU   r!   r   AddBetaRecognizeArgsToParserr   r   	__class__s     r    r!   zRecognizeLongRunningBeta.Args   s(    	
"$<B6J11&9r"   c                 |    t         t        |   ||      }| j                  j	                  ||j
                         |S r4   )rX   rU   r1   r   !UpdateBetaArgsInRecognitionConfigr%   r-   r.   r/   r0   r[   s       r    r1   z$RecognizeLongRunningBeta.MakeRequest   s6    ,d?hOG77gnnMNr"   )rM   rN   rO   r   rP   rQ   copyr   rS   r!   r1   __classcell__r[   s   @r    rU   rU   y   sC    "**'(66;;=-+: : r"   rU   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                   N     e Zd Zej                  ZdZe fd       Z fdZ xZ	S )RecognizeLongRunningAlpharV   c                     t         t        t          |       | j                  j	                  || j
                         y r4   )rX   rc   r!   r   AddAlphaRecognizeArgsToParserr   rZ   s     r    r!   zRecognizeLongRunningAlpha.Args   s.    	
#%>DVL2263??Kr"   c                 |    t         t        |   ||      }| j                  j	                  ||j
                         |S r4   )rX   rc   r1   r   "UpdateAlphaArgsInRecognitionConfigr%   r^   s       r    r1   z%RecognizeLongRunningAlpha.MakeRequest   s6    -t@xPG88w~~NNr"   )
rM   rN   rO   rU   rP   r   rS   r!   r1   r`   ra   s   @r    rc   rc      s1    $,,'+L L r"   rc   N)rP   
__future__r   r   r   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper   $googlecloudsdk.command_lib.ml.speechr	   r
   rE   ReleaseTracksReleaseTrackGACommandr   BETArU   rQ   ALPHArc   r5   r"   r    <module>rr      s    * &  ' , . ( 6 5
 +  D%%(()T,T\\ T, *T,n D%%**+5  ,$;  & & 7 D%%++, 8  -r"   