Stream Module

class sudio.stream.stream.Stream(other, obj, name=None, stream_type='multithreading', channel=None, process_type=PipelineProcessType.MAIN)

Bases: object

Initialize the Stream class for managing audio data streams.

Args: - other: An instance of the main audio processing class. - obj: An object representing the data stream (e.g., list, queue). - name: A name for the stream (optional). - stream_type: Type of streaming operation (‘multithreading’ or reserved for future versions). - channel: Channel index for controlling multi-channel streams (optional). - process_type: Type of stream processing PipelineProcessType (PipelineProcessType.MAIN, PipelineProcessType.MULTI_STREAM, PipelineProcessType.BRANCH, PipelineProcessType.QUEUE).

Raises: - StreamError: If there are issues with the provided parameters based on the selected processing mode.

Note: - This class provides a flexible mechanism for managing different types of audio data streams based on the specified

processing mode and stream type.

acquire()

Acquire the lock for thread-safe operations.

Note: - This method is used for thread synchronization in multithreading scenarios.

release()

Release the lock after thread-safe operations.

Note: - This method is used for releasing the lock acquired during thread-safe operations.

locked()

Check if the lock is currently held.

Returns: - bool: True if the lock is currently held, False otherwise.

Note: - This method is used to check the status of the lock for thread synchronization.

set(other)

Set the attributes of the current stream based on another stream.

Args: - other: Another instance of the Stream class.

Note: - This method allows setting the attributes of the current stream to match those of another stream.

type()

Get the type of stream processing.

Returns: - PipelineProcessType: The type of stream processing (MAIN, MULTI_STREAM, BRANCH, QUEUE).

Note: - This method returns the type of stream processing used by the current instance.

class sudio.stream.streamcontrol.StreamControl(master, record, on_stop, loop_mode, stream_mode)

Bases: object

The StreamControl class is defined to control the mainstream audio playback for a special ‘record’.

Initialize the StreamControl class to manage the mainstream audio playback for a specific ‘record’.

Args:

  • master: An instance of the main audio processing class.

  • record: A dictionary containing information about the audio file to be streamed.

  • on_stop: Callback function to execute when audio playback stops.

  • loop_mode: Boolean indicating whether to enable loop mode.

  • stream_mode: Type of streaming operation (e.g., ‘read’, ‘write’).

Attributes:

  • self._master: Reference to the main audio processing instance.

  • self._stream_type: Type of streaming operation.

  • self._stream_file: File object representing the audio file.

  • self._stream_file_size: Size of the audio file.

  • self._size_calculator: Lambda function to calculate the size of a data chunk.

  • self._stream_data_size: Size of the audio data to be streamed.

  • self._stream_data_pointer: Current position in the audio file.

  • self._stream_on_stop: Callback function for when audio playback stops.

  • self._stream_loop_mode: Boolean indicating whether loop mode is enabled.

  • self.duration: Duration of the audio file.

  • self._time_calculator: Lambda function to convert time to byte offset.

  • self._itime_calculator: Lambda function to convert byte offset to time.

Raises:

  • PermissionError: If attempting to initialize while another file is streaming.

Note:

  • This class facilitates the management of audio playback for a specific audio file, ensuring proper synchronization

and handling of playback-related operations.

time
isready()

Check if the stream is ready for playback.

Returns: - bool: True if ready, False otherwise

is_streaming()

Check if the stream is currently in the streaming state.

Returns: - bool: True if streaming, False otherwise

start()

Start the audio playback stream.

resume()

Resume the audio playback stream.

stop()

Stop the audio playback stream.

pause()

Pause the audio playback stream.

enable_loop()

Enable looping for the audio playback stream.

disable_loop()

Disable looping for the audio playback stream.

class sudio.stream.streamingtimecontroller.StreamingTimeController

Bases: object