The plugin that captures and plays sound using the multiplatform PortAudio library.
Add the following line to your deps
in mix.exs
. Run mix deps.get
.
{:membrane_portaudio_plugin, "~> 0.19.1"}
This package depends on the PortAudio library. The precompiled build will be pulled and linked automatically. However, should there be any problems, consider installing it manually.
When running on linux ALSA (alsa-lib) needs to be present on the system for the precompiled build to work. In most cases it's installed by default, however in case it's not present you can install it manually.
If cross-compiling for Nerves, both PortAudio and ALSA need to be present in the target Nerves system. See the Nerves docs for instructions on how to build a custom nerves system.
sudo apt-get install alsa
sudo apt-get install portaudio19-dev
pacman -S alsa-lib
pacman -S portaudio
brew install portaudio
The mix pa_devices
task prints available audio devices and their IDs, which you can pass to the Membrane.PortAudio.Source
or Membrane.PortAudio.Sink
.
The pipeline below should play a raw file to a default output device.
defmodule Membrane.ReleaseTest.Pipeline do
use Membrane.Pipeline
alias Membrane.PortAudio
@impl true
def handle_init(_ctx, _opts) do
structure =
child(:file_src, %Membrane.Element.File.Source{location: "file.raw"})
|> child(:pa_sink, PortAudio.Sink)
{[spec: structure], %{}}
end
end
And this one should forward sound from the default input to the default output. DO NOT USE WITHOUT HEADPHONES to avoid audio feedback.
defmodule Membrane.ReleaseTest.Pipeline do
use Membrane.Pipeline
alias Membrane.PortAudio
@impl true
def handle_init(_ctx, _opts) do
structure =
child(:pa_src, PortAudio.Source)
|> child(:pa_sink, PortAudio.Sink)
{[spec: structure], %{}}
end
end
Note: the endpoint_id option was recently renamed to device_id to be more in line with PortAudio's API.
Tests contain some cases that use PortAudio stuff instead of mocking. Such cases require the presence of at least one input and output sound card, thus they are disabled by default. To enable them, run
mix test --include soundcard
Copyright 2018, Software Mansion
Licensed under the Apache License, Version 2.0