
                            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  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)base)flags)utilc                   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)RecognizeGAzIGet transcripts of short (less than 60 seconds) audio from an audio file.a  Get a transcript of an audio file that is less than 60 seconds. You can use
an audio file that is on your local drive or a Google Cloud Storage URL.

If the audio is longer than 60 seconds, you will get an error. Please use
`{parent_command} recognize-long-running` instead.
a  To get a transcript of an audio file 'my-recording.wav':

    $ {command} 'my-recording.wav' --language-code=en-US

To get a transcript of an audio file in bucket 'gs://bucket/myaudio' with a
custom sampling rate and encoding that uses hints and filters profanity:

    $ {command} 'gs://bucket/myaudio' \
        --language-code=es-ES --sample-rate=2200 --hints=Bueno \
        --encoding=OGG_OPUS --filter-profanity
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                         y )Njson)display_info	AddFormatflags_mapperAddRecognizeArgsToParserAPI_VERSION)clsparsers     "lib/surface/ml/speech/recognize.pyArgszRecognizeGA.Args?   s0    
!!&)--fcooF    c                     |j                  t        j                  |j                  | j                        | j
                  j                  ||            S )N)audioconfig)RecognizeRequestr	   GetRecognitionAudioFromPathr   r   r   MakeRecognitionConfig)selfargsmessagess      r   MakeRequestzRecognizeGA.MakeRequestD   sL    $$..tzz4;K;KL  66tXF % H Hr   c                     t        j                  t        j                  | j                        }| j                  ||j                        | _        |j                  j                  | j                        S )zRun 'ml speech recognize'.

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

    Returns:
      Nothing.
    )
r   GetClientInstancer	   
SPEECH_APIr   r%   MESSAGES_MODULE_requestspeech	Recognize)r"   r#   clients      r   RunzRecognizeGA.RunI   sS     ##DOOT5E5EFF$$T6+A+ABDM==""4==11r   c                 B    t        j                  | j                         y N)r	   MaybePrintSttUiLinkr*   )r"   unused_resources_were_displayeds     r   EpilogzRecognizeGA.EpilogW   s    T]]+r   N)__name__
__module____qualname____doc__detailed_helpr   r   RecognizeArgsToRequestMapperr   classmethodr   r%   r.   r3    r   r   r   r      sV    Q/-: +3335,G GH
2,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 )RecognizeBeta	v1p1beta1c                 j    t         t        t          |       | j                  j	                  |       y r0   )superr=   r   r   AddBetaRecognizeArgsToParserr   r   	__class__s     r   r   zRecognizeBeta.Argsb   s&    	-,V411&9r   c                 |    t         t        |   ||      }| j                  j	                  ||j
                         |S r0   )r@   r=   r%   r   !UpdateBetaArgsInRecognitionConfigr   r"   r#   r$   requestrC   s       r   r%   zRecognizeBeta.MakeRequestg   s5    M44T8DG77gnnMNr   )r4   r5   r6   r   r7   r8   copyr   r:   r   r%   __classcell__rC   s   @r   r=   r=   [   sC    '++002-+: : 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                   N     e Zd Zej                  ZdZe fd       Z fdZ xZ	S )RecognizeAlphar>   c                     t         t        t          |       | j                  j	                  || j
                         y r0   )r@   rL   r   r   AddAlphaRecognizeArgsToParserr   rB   s     r   r   zRecognizeAlpha.Argsy   s,    	...v62263??Kr   c                 |    t         t        |   ||      }| j                  j	                  ||j
                         |S r0   )r@   rL   r%   r   "UpdateAlphaArgsInRecognitionConfigr   rF   s       r   r%   zRecognizeAlpha.MakeRequest~   s5    ND5dHEG88w~~NNr   )
r4   r5   r6   r=   r7   r   r:   r   r%   rI   rJ   s   @r   rL   rL   s   s1    !!'+L L r   rL   N)r7   
__future__r   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   $googlecloudsdk.command_lib.ml.speechr   r	   ReleaseTracksReleaseTrackGACommandr   BETAr=   r8   ALPHArL   r;   r   r   <module>r[      s    * &  ' , ( 6 5 D%%(()<,$,, <, *<,~ D%%**+K  ,"0  O , D%%++,]  -r   