pipewire_python API documentation

Edit on GitHub

# pipewire_python

## Description

PIPEWIRE provides a low-latency, graph based processing engine on top of audio and video devices that can be used to support the use cases currently handled by both pulseaudio and JACK. PipeWire was designed with a powerful security model that makes interacting with audio and video devices from containerized applications easy, with supporting Flatpak applications being the primary goal. Alongside Wayland and Flatpak we expect PipeWire to provide a core building block for the future of Linux application development.

pipewire_python controlls `pipewire` via terminal, creating shell commands and executing them as required.

🎹 There are two ways to manage the python package:

1. NO_ASYNC: this way works as expected with delay time between `pipewire_python` and the rest of your code.

2. ASYNC: [⚠️Not yet implemented] this way works delegating the task to record or to play a song file in background. Works with threads.

3. MULTIPROCESS: [⚠️Not yet implemented] Works with processes.

📄 More information about `pipewire` and it's API's:

- 🎵 Asyncio https://docs.python.org/3/library/asyncio-subprocess.html
- 🎵 Pipewire APIs https://www.linuxfromscratch.org/blfs/view/cvs/multimedia/pipewire.html
- 🎵 APIs example https://fedoraproject.org/wiki/QA:Testcase_PipeWire_PipeWire_CLI

Developed with ❤️ by Pablo Diaz

## Install via

    pip3 install pipewire_python # or pip

## Tutorial

    from pipewire_python.controller import Controller

    # PLAYBACK: normal way
    audio_controller = Controller()
    audio_controller.set_config(rate=384000,
                                channels=2,
                                _format='f64',
                                volume=0.98,
                                quality=4,
                                # Debug
                                verbose=True)
    audio_controller.playback(audio_filename='docs/beers.wav')

    # RECORD: normal way
    audio_controller = Controller(verbose=True)
    audio_controller.record(audio_filename='docs/5sec_record.wav',
                            timeout_seconds=5,
                            # Debug
                            verbose=True)

View Source

     1"""
     2## Description
     3
     4[PIPEWIRE](https://pipewire.org/) provides a low-latency, graph based processing engine
     5on top of audio and video devices that can be used to
     6support the use cases currently handled by both pulseaudio
     7and JACK. PipeWire was designed with a powerful security model
     8that makes interacting with audio and video devices from
     9containerized applications easy, with supporting Flatpak
    10applications being the primary goal. Alongside Wayland and
    11Flatpak we expect PipeWire to provide a core building block
    12for the future of Linux application development.
    13
    14[pipewire_python](https://pypi.org/project/pipewire_python/)
    15controlls `pipewire` via terminal, creating shell commands and executing them as required.
    16
    17🎹 There are two ways to manage the python package:
    18
    191. NO_ASYNC: this way works as expected with delay time between
    20`pipewire_python` and the rest of your code.
    21
    222. ASYNC: [⚠️Not yet implemented] this way works delegating the task to record or to play
    23a song file in background. Works with threads.
    24
    253. MULTIPROCESS: [⚠️Not yet implemented] Works with processes.
    26
    27
    28📄 More information about `pipewire` and it's API's:
    29
    30- 🎵 Asyncio https://docs.python.org/3/library/asyncio-subprocess.html
    31- 🎵 Pipewire APIs https://www.linuxfromscratch.org/blfs/view/cvs/multimedia/pipewire.html
    32- 🎵 APIs example https://fedoraproject.org/wiki/QA:Testcase_PipeWire_PipeWire_CLI
    33
    34Developed with ❤️ by Pablo Diaz
    35
    36
    37##  Install via
    38```bash
    39
    40pip3 install pipewire_python # or pip
    41```
    42
    43## Tutorial
    44
    45
    46```python
    47from pipewire_python.controller import Controller
    48
    49# PLAYBACK: normal way
    50audio_controller = Controller()
    51audio_controller.set_config(rate=384000,
    52                            channels=2,
    53                            _format='f64',
    54                            volume=0.98,
    55                            quality=4,
    56                            # Debug
    57                            verbose=True)
    58audio_controller.playback(audio_filename='docs/beers.wav')
    59
    60# RECORD: normal way
    61audio_controller = Controller(verbose=True)
    62audio_controller.record(audio_filename='docs/5sec_record.wav',
    63                        timeout_seconds=5,
    64                        # Debug
    65                        verbose=True)
    66
    67```
    68"""
    69
    70__version__ = "0.2.1"
    71
    72import sys
    73
    74if sys.platform == "linux":
    75    # from pipewire_python.controller import *
    76    pass
    77else:
    78    raise NotImplementedError("By now, Pipewire only runs on linux.")