examples.communication_patterns package

Submodules

examples.communication_patterns.request_reply_example module

A message requester and replier for native Python objects, and images using OpenCV.

This script demonstrates the capability to transmit native Python objects and images using the MiddlewareCommunicator within the Wrapyfi library. The communication follows the REQ/REP pattern allowing message requesting and replying functionalities between processes or machines.

Demonstrations:
  • Using the NativeObject, Image and AudioChunk messages

  • Transmitting a Python object, an image, and audio chunk

  • Applying the REQ/REP pattern with persistence

  • Reading and transmitting an OpenCV image which can be loaded, resized, and displayed on the client and server ends

  • Reading and transmitting a sounddevice (PortAudio with NumPy) audio chunk which can be played back on the client and server ends

Requirements:
  • Wrapyfi: Middleware communication wrapper (refer to the Wrapyfi documentation for installation instructions)

  • YARP, ROS, ROS 2, ZeroMQ (refer to the Wrapyfi documentation for installation instructions)

  • OpenCV: Used for handling and creating images (installed with Wrapyfi)

  • sounddevice, soundfile: Used for handling audio

Install using pip:

pip install sounddevice soundfile

Run:
# Alternative 1: Image and NativeObject transmission

# On machine 1 (or process 1): Requester sends a message and awaits a reply (image and native object)

python3 request_reply_example.py --mode request --stream image

# On machine 2 (or process 2): Replier waits for a message and sends a reply (image and native object)

python3 request_reply_example.py --mode reply --stream image

# Alternative 2: AudioChunk and NativeObject transmission

# On machine 1 (or process 1): Requester sends a message and awaits a reply (audio chunk and native object)

python3 request_reply_example.py --mode request --stream audio

# On machine 2 (or process 2): Replier waits for a message and sends a reply (audio chunk and native object)

python3 request_reply_example.py --mode reply --stream audio

class examples.communication_patterns.request_reply_example.ReqRep[source]

Bases: MiddlewareCommunicator

send_img_message(msg=None, img_width=320, img_height=240, mware=None, *args, **kwargs)[source]

Exchange messages with OpenCV images and other native Python objects.

send_aud_message(msg=None, aud_rate=-1, aud_chunk=-1, aud_channels=2, mware=None, *args, **kwargs)[source]

Exchange messages with sounddevice audio chunks and other native Python objects.

examples.communication_patterns.request_reply_example.parse_args()[source]

Parse command line arguments.

examples.communication_patterns.request_reply_example.sound_play(my_aud, blocking=True, device=0)[source]

Play audio using sounddevice.

Parameters:
  • my_aud – Tuple[np.ndarray, int]: The audio chunk and sampling rate to play

  • blocking – bool: Whether to block the execution until the audio is played

  • device – int: The sound device to use for audio playback

Returns:

bool: Whether the audio was played successfully

examples.communication_patterns.request_reply_example.main(args)[source]

Module contents