Bluetooth: Difference between revisions

From NixOS Wiki
imported>Samueldr
m Updates sectoin name to External resources, fixes article name in link
imported>Samueldr
m re-worked the page; added non-gui and gui variants of pairing and for pulseaudio management.
Line 1: Line 1:
== Bluetooth headsets with Pulseaudio ==


<syntaxhighlight lang="nix">{
== Pairing ==
  hardware.pulseaudio = {
 
    enable = true;
Bigger desktop environments will usually provide a bluetooth management system.
    package = pkgs.pulseaudioFull;
 
  };
{{expansion}}
  hardware.bluetooth.enable = true;
}</syntaxhighlight>
After updating the configuration


<syntaxhighlight lang="bash">nixos-rebuild switch</syntaxhighlight>
Alternatively, using <code>pkgs.blueman</code>, it is possible to get a tray icon <code>blueman-applet</code> or use the manager directly using <code>blueman-manager</code>.
I had to restart the system for pulseaudio to load the bluetooth module.


<code>pactl list</code> should show the bluetooth module.
=== Pairing without GUI tools ===


As I'm not using a desktop-manager I've configured the device from the command line following [https://wiki.archlinux.org/index.php/Bluetooth_Headset ArchLinux instructions]
When not using a desktop-manager, configuring the device from the command line can be done following the [https://wiki.archlinux.org/index.php/Bluetooth_Headset ArchWiki instructions], as follows.


<syntaxhighlight lang="console">$ bluetoothctl
<syntaxhighlight lang="console">$ bluetoothctl
Line 26: Line 21:
[bluetooth] # connect [hex-address]</syntaxhighlight>
[bluetooth] # connect [hex-address]</syntaxhighlight>


I've then played some audio and opened configured PulseAudio using pavucontrol. I changed the headset profile to "High Fidelity Playback (A2DP Sink)" for decent audio quality.
== Bluetooth headsets with PulseAudio ==
 
The package used for PulseAudio has to be <code>pkgs.pulseaudioFull</code>, which includes bluetooth support.
 
<syntaxhighlight lang="nix">{
  hardware.pulseaudio = {
    enable = true;
    package = pkgs.pulseaudioFull;
  };
  hardware.bluetooth.enable = true;
}</syntaxhighlight>
 
{{evaluate}}
 
Either restart the system for PulseAudio to load the bluetooth module, or restart your local instance of PulseAudio by running <code>pkill ^pulseaudio$</code>.
 
Ensure PulseAudio has loaded bluetooth modules by using <code>pactl list | grep -i Name.*module.*blue</code>. Bluetooth modules should be present in the list.
 
=== Managing the audio interface ===
 
Using <code>pavucontrol</code>, the headset profile can be changed to ''"High Fidelity Playback (A2DP Sink)"'' in the ''Configuration'' tab.
 
The default sink can be changed in the ''Output Devices'' tab. clicking on the right most button, which it title ''Set as fallback''.
 
==== Managing the audio interface using <code>pacmd</code> ====
 
Setting the card to A2DP
 
<syntaxhighlight lang="console">
$ pacmd set-card-profile "$(pactl list cards short | egrep -o bluez_card[[:alnum:]._]+)" a2dp_sink
</syntaxhighlight>
 
Setting the bluetooth sink as default
 
<syntaxhighlight lang="console">
$ pacmd set-default-sink "$(pactl list sinks short | egrep -o bluez_sink[[:alnum:]._]+)"
</syntaxhighlight>


== External resources ==
== External resources ==


* [http://anderspapitto.com/posts/2016-11-07-scripting_pulseaudio_bluetooth_jack.html Scripting pulseaudio, bluetooth, jack]
* [http://anderspapitto.com/posts/2016-11-07-scripting_pulseaudio_bluetooth_jack.html Scripting pulseaudio, bluetooth, jack]

Revision as of 20:11, 14 October 2017

Pairing

Bigger desktop environments will usually provide a bluetooth management system.

Alternatively, using pkgs.blueman, it is possible to get a tray icon blueman-applet or use the manager directly using blueman-manager.

Pairing without GUI tools

When not using a desktop-manager, configuring the device from the command line can be done following the ArchWiki instructions, as follows.

$ bluetoothctl
[bluetooth] # power on
[bluetooth] # agent on
[bluetooth] # default-agent
[bluetooth] # scan on
...put device in pairing mode and wait [hex-address] to appear here...
[bluetooth] # pair [hex-address]
[bluetooth] # connect [hex-address]

Bluetooth headsets with PulseAudio

The package used for PulseAudio has to be pkgs.pulseaudioFull, which includes bluetooth support.

{
  hardware.pulseaudio = {
    enable = true;
    package = pkgs.pulseaudioFull;
  };
  hardware.bluetooth.enable = true;
}

Either restart the system for PulseAudio to load the bluetooth module, or restart your local instance of PulseAudio by running pkill ^pulseaudio$.

Ensure PulseAudio has loaded bluetooth modules by using pactl list | grep -i Name.*module.*blue. Bluetooth modules should be present in the list.

Managing the audio interface

Using pavucontrol, the headset profile can be changed to "High Fidelity Playback (A2DP Sink)" in the Configuration tab.

The default sink can be changed in the Output Devices tab. clicking on the right most button, which it title Set as fallback.

Managing the audio interface using pacmd

Setting the card to A2DP

$ pacmd set-card-profile "$(pactl list cards short | egrep -o bluez_card[[:alnum:]._]+)" a2dp_sink

Setting the bluetooth sink as default

$ pacmd set-default-sink "$(pactl list sinks short | egrep -o bluez_sink[[:alnum:]._]+)"

External resources