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:

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)

Linking Ports

from pipewire_python import link

inputs = link.list_inputs()
outputs = link.list_outputs()

# Connect the last output to the last input -- during testing it was found that
# Midi channel is normally listed first, so this avoids that.
source = outputs[-1]
sink = inputs[-1]
source.connect(sink)

# Fun Fact! You can connect/disconnect in either order!
sink.disconnect(source) # Tada!

# Default Input/Output links will be made with left-left and right-right
# connections; in other words, a straight stereo connection.
# It's possible to manually cross the lines, however!
source.right.connect(sink.left)
source.left.connect(sink.right)
  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 
 16and executing them as required.
 17
 18🎹 There are two ways to manage the python package:
 19
 201. NO_ASYNC: this way works as expected with delay time between 
 21`pipewire_python` and the rest of your code.
 22
 232. ASYNC: [⚠️Not yet implemented] this way works delegating
 24the task to record or to play
 25a song file in background. Works with threads.
 26
 273. MULTIPROCESS: [⚠️Not yet implemented] Works with processes.
 28
 29
 30📄 More information about `pipewire` and it's API's:
 31
 32- 🎵 Asyncio https://docs.python.org/3/library/asyncio-subprocess.html
 33- 🎵 Pipewire APIs https://www.linuxfromscratch.org/blfs/view/cvs/multimedia/pipewire.html
 34- 🎵 APIs example https://fedoraproject.org/wiki/QA:Testcase_PipeWire_PipeWire_CLI
 35
 36Developed with ❤️ by Pablo Diaz
 37
 38
 39##  Install via
 40```bash
 41
 42pip3 install pipewire_python # or pip
 43```
 44
 45## Tutorial
 46
 47
 48```python
 49from pipewire_python.controller import Controller
 50
 51# PLAYBACK: normal way
 52audio_controller = Controller()
 53audio_controller.set_config(rate=384000,
 54                            channels=2,
 55                            _format='f64',
 56                            volume=0.98,
 57                            quality=4,
 58                            # Debug
 59                            verbose=True)
 60audio_controller.playback(audio_filename='docs/beers.wav')
 61
 62# RECORD: normal way
 63audio_controller = Controller(verbose=True)
 64audio_controller.record(audio_filename='docs/5sec_record.wav',
 65                        timeout_seconds=5,
 66                        # Debug
 67                        verbose=True)
 68
 69```
 70
 71### Linking Ports
 72
 73```python
 74from pipewire_python import link
 75
 76inputs = link.list_inputs()
 77outputs = link.list_outputs()
 78
 79# Connect the last output to the last input -- during testing it was found that
 80# Midi channel is normally listed first, so this avoids that.
 81source = outputs[-1]
 82sink = inputs[-1]
 83source.connect(sink)
 84
 85# Fun Fact! You can connect/disconnect in either order!
 86sink.disconnect(source) # Tada!
 87
 88# Default Input/Output links will be made with left-left and right-right
 89# connections; in other words, a straight stereo connection.
 90# It's possible to manually cross the lines, however!
 91source.right.connect(sink.left)
 92source.left.connect(sink.right)
 93```
 94"""
 95
 96__version__ = "0.2.3"
 97
 98import sys
 99
100if sys.platform == "linux":
101    # from pipewire_python.controller import *
102    pass
103else:
104    raise NotImplementedError("By now, Pipewire only runs on linux.")