Beispiel #1
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Raises:
      googlecloudsdk.api_lib.util.exceptions.HttpException, if there is an
          error returned by the API.

    Returns:
      The results of the Get request.
    """
        operation_ref = resources.REGISTRY.Parse(
            args.operation, collection='speech.operations')
        speech_client = speech_api_client.SpeechClient()
        return speech_client.DescribeOperation(operation_ref)
    encoding: None|str, the encoding of the audio.

  Raises:
    googlecloudsdk.api_lib.ml.speech.exceptions.AudioException: if the audio
        file is not recognized as local or a valid Google Cloud Storage URL.
    googlecloudsdk.api_lib.util.exceptions.HttpException: arbitrary errors
        returned by the API.
    googlecloudsdk.api_lib.util.waiter.OperationError: if polling the operation
        results in an operation with an error.

  Returns:
    the result of the command (speech_v1_messages.RecognizeResponse,
        speech_v1_messages.Operation, or speech_v1_messages.LongRunningRecognize
        Response).
  """
    client = speech_api_client.SpeechClient()
    audio = client.GetAudio(path_to_audio)
    config = client.GetRecognitionConfig(language,
                                         max_alternatives,
                                         sample_rate=sample_rate,
                                         encoding=encoding,
                                         filter_profanity=filter_profanity,
                                         hints=hints)
    result = client.Recognize(audio, config, long_running)
    if not long_running or async:
        return result
    operation_ref = resources.REGISTRY.Parse(result.name,
                                             collection='speech.operations')
    return client.WaitOperation(operation_ref)