olivepy.messaging package

Submodules

olivepy.messaging.msgutil module

Contains data structures that map message_type enum values to protobuf types and vice versa. Should be updated whenever new message types are added.

exception olivepy.messaging.msgutil.AllowableErrorFromServer

Bases: Exception

This exception means that the server could not complete a request; however, the reason it could not do isn’t considered an error. This special case most often occurs when requesting analysis of a submission that contains no speech, in which case the analysis could not complete since there was not speech and not due to an error running the plugin. Otherwise, this is identical to Python’s plain old Exception

class olivepy.messaging.msgutil.AudioTransferType(value)

Bases: enum.Enum

The method used to send audio to the OLIVE server. There are three options for sending audio to the server:

1. AUDIO_PATH: Send the path of the audio file to the server. NOTE: If using this option, the path must be accessible to the server

2. AUDIO_DECODED: Send the audio as a buffer of decoded samples (PCM-16). This option is not well supported by this client since it does not

  1. AUDIO_SERIALIZED: Send the file as a binary buffer

AUDIO_DECODED = 2
AUDIO_PATH = 1
AUDIO_SERIALIZED = 3
exception olivepy.messaging.msgutil.ExceptionFromServer

Bases: Exception

This exception means that an error occured on the server side, and this error is

being sent “up the chain” on the client side. Otherwise, it is identical to Python’s plain old Exception

olivepy.messaging.msgutil.get_uuid()
olivepy.messaging.msgutil.package_audio(audio_msg, audio_data, annotations=None, selected_channel=None, mode=AudioTransferType.AUDIO_PATH, num_channels=None, sample_rate=None, num_samples=None, validate_local_path=True)
Parameters
  • audio_msg (Audio) – the Olive Audio message to populate

  • audio_data (AnyStr) – either a filename or binary buffer

  • annotations – a list of tuple start/end regions (in seconds)

  • selected_channel – if audio_data is multi-channel then select this channel for processing

  • mode – the submission mode: pathname, serialized, samples

  • num_channels – the number of channels in the audio

  • sample_rate – the sample rate of the audio

  • num_samples – the number of samples in the audio.

  • validate_local_path – if sending audio as a path, throw an exception if the file does not exist. We let this be an option for the possible case where the client may want to provide a path on the server’s filesystem, but not the local filesystem.

Returns

a valid Audio message

:raises Exception if unable to package the audio for the specified mode.

olivepy.messaging.msgutil.serialize_audio(filename)

Helper function used to read in an audio file and output a serialized buffer. Can be used with package_audio() when using the AUDIO_SERIALIZED mode and the audio input has not already been serialized

Parameters

filename (str) – the local path to the file to serialize

Return type

AnyStr

Returns

the contents of the file as a byte buffer, otherwise an exception if the file can not be opened. This buffer contains the raw content of the file, it does NOT contain encoded samples

olivepy.messaging.olive_pb2 module

olivepy.messaging.response module

class olivepy.messaging.response.OliveClassStatusResponse

Bases: olivepy.messaging.response.OliveServerResponse

The container/wrapper for WorkflowClassStatusResult from an OLIVE server (when using the AsyncOliveClient). This is intended to make it easier for clients to handle the traditional (original) protobuf message results (such as RegionScorerResult) returned from the server.

get_response_as_json()
get_workflow_type()

Return the type of workflow done in this response (analysis, enrollment, adaptation)

Returns

A WorkflowType: WORKFLOW_ANALYSIS_TYPE, WORKFLOW_ENROLLMENT_TYPE, WORKFLOW_ADAPT_TYPE or an Exception if an non-workflow response message was wrapped

parse_from_response(request, response, message)

Create this response from the :param request: :param response: :param message: :return:

to_json(indent=None)

Generate the response as a JSON string :param indent: if a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation. A negative value will return the JSON document

Returns

the Workflow response as as JSON string:

class olivepy.messaging.response.OliveServerResponse

Bases: object

The default container/wrapper for responses from an OLIVE server (when using the AsyncOliveClient). This is intended to make it easier for clients to handle the traditional (original) protobuf message results (such as RegionScorerResult) returned from the server.

get_error()
get_response()

The Protobuf message returned from the OLIVE server :return:

get_response_as_json()
get_workflow_type()

Return the type of workflow done in this response (analysis, enrollment, adaptation)

Returns

A WorkflowType: WORKFLOW_ANALYSIS_TYPE, WORKFLOW_ENROLLMENT_TYPE, WORKFLOW_ADAPT_TYPE or an Exception if an non-workflow response message was wrapped

is_error()
is_successful()
parse_from_response(request, response, message)

Create this response from the :param request: :param response: :param message: :return:

to_json(indent=None)

Generate the response as a JSON string :param indent: if a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation. A negative value will return the JSON document

Returns

the response as as JSON string:

class olivepy.messaging.response.OliveWorkflowActualizedResponse

Bases: olivepy.messaging.response.OliveServerResponse

Extracts info from an actualized workflow definition

get_analysis_jobs()

Return the names of analysis jobs. Typically a workflow has just one job with multiple tasks, the most likely reason to have multiple jobs is for workflows using multi-channel audio so there may be a set of job tasks for each channel of audio submitted.

Returns

a list of job names in the analysis

get_analysis_tasks(job_name=None)
get_request_jobs(workflow_type)

return the jobs in the original request for the specified analysis type

Parameters

workflow_type – the type of workflow (i.e. WORKFLOW_ANALYSIS_TYPE)

Returns

the list of jobs for this type

get_response_as_json()
get_workflow()
is_allowable_error()
Returns

true if this response failed with an allowable error

parse_from_response(request, response, message)

Create this response from the :param request: :param response: :param message: :return:

to_json(indent=None)

Generate the response as a JSON string :param indent: if a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation. A negative value will return the JSON document

Returns

the Workflow response as as JSON string:

class olivepy.messaging.response.OliveWorkflowAnalysisResponse

Bases: olivepy.messaging.response.OliveServerResponse

The default container/wrapper for responses from an OLIVE server (when using the AsyncOliveClient). This is intended to make it easier for clients to handle the traditional (original) protobuf message results (such as RegionScorerResult) returned from the server.

get_analysis_job_result(job_name=None)
get_analysis_jobs()

Return the names of analysis jobs. Typically a workflow has just one job with multiple tasks, the most likely reason to have multiple jobs is for workflows using multi-channel audio so there may be a set of job tasks for each channel of audio submitted.

Returns

a list of job names in the analysis

get_analysis_task_result(job_name, task_name)

Get the result for the specified job_name and task_name, also include the data used for this task. If the workflow analyzes each channel in multi-channel data then there can be multiple jobs with the same name.

Parameters
  • job_name – for convenience can be None, since there is normally only one job. But if the workflow has multiple jobs then a valid name must be specified.

  • task_name – the name to the task

Returns

a list of dictionaries, where each dictionary in the list includes the results for the specified task and a list of the data analyzed by this task, such as [ {task_name:{}, data:[] }]

get_analysis_tasks(job_name=None)
get_failed_tasks(job_name=None)
get_request_jobs(workflow_type)

return the jobs in the original request for the specified analysis type

Parameters

workflow_type – the type of workflow (i.e. WORKFLOW_ANALYSIS_TYPE)

Returns

the list of jobs for this type

get_response_as_json()
is_allowable_error()
Returns

true if this response failed with an allowable error

parse_from_response(request, response, message)

Create this response from the :param request: :param response: :param message: :return:

to_json(indent=None)

Generate the workflow as a JSON string :indent: if a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation. A negative value will return the JSON document

Returns

the Workflow Definition as as JSON string:

class olivepy.messaging.response.OliveWorkflowEnrollmentResponse

Bases: olivepy.messaging.response.OliveServerResponse

The container/wrapper for responses from an OLIVE server (when using the AsyncOliveClient) for enrollment. This is intended to make it easier for clients to handle the traditional (original) protobuf message results (such as RegionScorerResult) returned from the server.

get_response_as_json()
is_allowable_error()
Returns

true if this message failed with an allowable error

parse_from_response(request, response, message)

Create this response from the :param request: :param response: :param message: :return:

to_json(indent=None)

Generate the response as a JSON string :param indent: if a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation. A negative value will return the JSON document

Returns

the Workflow response as as JSON string:

olivepy.messaging.response.get_workflow_job_names(workflow_definition, workflow_type)

parse a workflow definition, returning a list of job definition name (job_name)

return [job_name] for the requested workflow_type

olivepy.messaging.response.get_workflow_job_tasks(jobs, job_name=None)

Fetch the tasks from a job

Parameters
  • jobs – a dictionary of WorkflowTasks, indexed by a job names

  • job_name – find tasks that belong to a job having this name. This can be None if there is only one job

Returns

a dictionary of WorkflowTask indexed by the task’s consumer_result_label for the specified job. An exception is thrown if there are multiple jobs but no job_name was specified

olivepy.messaging.response.get_workflow_jobs(workflow_definition, workflow_type)

parse a workflow definition, returning a dictionary indexed job (definition) name (job_name) and a list of WorkflowTask elements.

Parameters
  • workflow_definition – find jobs in this workflow definition

  • workflow_type – the type of workflow order (analysis, enrollment, unenrollment)

return {job_name: [WorkflowTask]} for the requested workflow_type

olivepy.messaging.response.sort_global_scores(score)

Module contents