async def longrunning_recognize_with_uploader(
            self,
            source,
            config: dict,
            object_name: str = None,
            dict_format=True, metadata=None,
            with_response_meta=False,
    ):
        """
        Recognize audio in long running mode.
            :param source: path to audio or fileobj
            :param config: dict conforming to long_running_recognition_schema
            :param object_name: name for object in storage (default: 'default_name_<utcnow>')
            :param dict_format: dict response instead of proto object
            :param metadata: configure own metadata
            :param with_response_meta: return response with metadata
        """
        validate(config, config_schema.long_running_recognition_config_schema)
        uri = await self._uploader.upload(source, object_name)

        request = self._stub.LongRunningRecognize(
            get_proto_longrunning_request(uri, config),
            metadata=metadata if metadata else self._metadata.metadata
        )

        response = await request
        if with_response_meta:
            response_meta = await request.initial_metadata()
            return (*response_format(response, dict_format, response_meta), uri)
        else:
            return response_format(response, dict_format), uri
Exemple #2
0
    def longrunning_recognize(self,
                              source,
                              config,
                              dict_format=True,
                              metadata=None,
                              with_response_meta=False):
        """
        Recognize audio in long running mode.
            :param source: uri or buffer source
            :param config: dict conforming to long_running_recognition_schema
            :param dict_format: dict response instead of proto object
            :param metadata: configure own metadata
            :param with_response_meta: return response with metadata

        """
        validate(config, config_schema.long_running_recognition_config_schema)
        if self._uploader.is_storage_uri(source):
            buffer = source
        else:
            buffer = get_buffer(source)

        response, unary_obj = self._stub.LongRunningRecognize.with_call(
            get_proto_longrunning_request(buffer, config),
            metadata=metadata if metadata else self._metadata.metadata)

        response_meta = unary_obj.initial_metadata(
        ) if with_response_meta else None
        return response_format(response, dict_format, response_meta)
 def list_operations(self, request: dict, metadata=None, dict_format=True):
     """
     Return list with operations
         :param request: configure list operation request
         :param metadata: configure own metadata
         :param dict_format: dict response instead of proto object
     """
     validate(request, config_schema.list_operations_config_schema)
     response = self._stub.ListOperations(
         get_proto_list_operations_request(request),
         metadata=metadata if metadata else self._metadata.metadata,
     )
     return response_format(response, dict_format)
 def get_operation(self, request: dict, metadata=None, dict_format=True):
     """
     Return operation by operation ID
         :param request: operation request
         :param metadata: configure own metadata
         :param dict_format: dict response instead of proto object
     """
     validate(request, config_schema.get_operation_config_schema)
     response = self._stub.GetOperation(
         get_proto_operation_request(request),
         metadata=metadata if metadata else self._metadata.metadata,
     )
     return response_format(response, dict_format)
 async def wait_operation(self,
                          request: dict,
                          metadata=None,
                          dict_format=True):
     """
     Wait operation
         :param request: wait operation request
         :param metadata:  configure own metadata
         :param dict_format: dict response instead of proto object
     """
     validate(request, config_schema.wait_operation_config_schema)
     response = await self._stub.WaitOperation(
         get_proto_wait_operation_request(request),
         metadata=metadata if metadata else self._metadata.metadata,
     )
     return response_format(response, dict_format)
 def cancel_operation(self,
                      operation_filter: dict,
                      metadata=None,
                      dict_format=True):
     """
     Cancel all operations matching operation filter
         :param operation_filter: configure operation filter
         :param metadata: configure own metadata
         :param dict_format: dict response instead of proto object
     """
     validate(operation_filter,
              config_schema.operation_filter_config_schema)
     response = self._stub.CancelOperation(
         get_proto_delete_operation_request(operation_filter),
         metadata=metadata if metadata else self._metadata.metadata,
     )
     return response_format(response, dict_format)
    async def recognize(self, source, config, metadata=None, dict_format=True, with_response_meta=False):
        """
        Recognize whole audio and then return all responses.
            :param source: path to audio file or buffer with audio
            :param config: dict conforming to recognition_config_schema
            :param dict_format: dict response instead of proto object
            :param with_response_meta: return response with metadata
            :param metadata: configure own metadata
        """
        validate(config, config_schema.recognition_config_schema)
        buffer = get_buffer(source)

        request = self._stub.Recognize(
            get_proto_request(buffer, config),
            metadata=metadata if metadata else self._metadata.metadata
        )

        response_meta = await request.initial_metadata() if with_response_meta else None
        response = await request
        return response_format(response, dict_format, response_meta)