Difference between revisions of "Bluetooth headset"

From ArchWiki
Jump to: navigation, search
(ALSA, BLUEZ5, and PULSEAUDIO method: Trying to clean up the article per comments.)
(ALSA, BLUEZ5, and PULSEAUDIO method: Trying to fix the noted poor writing section. Overall structure changes.)
Line 119: Line 119:
 
If you receive this error whilst trying to pair your headset with your system using bluez-simple-agent, then you can try to restart your system and use the graphical bluez applet of your desktop environment.
 
If you receive this error whilst trying to pair your headset with your system using bluez-simple-agent, then you can try to restart your system and use the graphical bluez applet of your desktop environment.
  
== ALSA, BLUEZ5, and PULSEAUDIO  method ==
+
== ALSA, BLUEZ5, and PULSEAUDIO  Method ==
 
{{Poor writing|Using first person, should use package templates, see [[Help:Style]] and related.}}
 
{{Poor writing|Using first person, should use package templates, see [[Help:Style]] and related.}}
  
I'm not an expert in any of this but this how I muddled my way through this process. Perhaps someone can tighten up the install methodFWIW, I was using a T61p laptop and SoundBot 220 bluetooth headset.
+
Bluez5, pulseaudio and ALSA work together to allow a wireless bluetooth headset to play audioThe following method works with a Lenovo T61p laptop and SoundBot SB220 wireless bluetooth headset.  The required software stack is extensive and failure to include all components can produce errors which are difficult to understand.  The following list of software might not be the minimum required set and needs to be examined more closely.
  
Install Alsa and associated libraries.
+
=== Install Software Packages ===
*alsa-lib 1.0.27.2-1
+
*alsa-plugins 1.0.27-2
+
*alsa-tools 1.0.27-5
+
*alsa-utils 1.0.27.2-1
+
  
Install Bluez5
+
The core software components are ALSA, Bluez5, Pulseaudio. However there are additional libraries which are required. As well as a player which can play audio files.  The following section lists the software packages installed in order to connect the headset and play audio over the headset.
*bluez 5.11-1
+
*bluez-libs 5.11-1
+
*bluez-utils 5.11-1
+
  
Install Pulseaudio
 
*libcanberra-pulse 0.30-4
 
*pulseaudio-git v4.0.318.gce304d6-1
 
  
Optional, I chose to use audacious as my player
+
==== Install Alsa and associated libraries.====
*audacious 3.4.2-1
+
*audacious-plugins 3.4.2-1
+
  
At one point, I needed a ton of python and Qt codeI hate to dump this here, but you might as well see it all.
+
ALSA works with the linux kernel to provide audio services to user mode softwareThe following packages are used.
*python 3.3.3-1
+
*python-dbus 1.2.0-1
+
*python-dbus-common 1.2.0-1
+
*python-lxml 3.2.3-1
+
*python-pyqt4 4.10.3-1
+
*python-sip 4.15.3-1
+
*python-xdg 0.25-1
+
*python2 2.7.6-1
+
*python2-beaker 1.6.4-1
+
*python2-cairo 1.10.0-1
+
*python2-dbus 1.2.0-1
+
*python2-gobject 3.10.2-1
+
*python2-gobject2 2.28.6-9
+
*python2-mako 0.9.0-1
+
*python2-markupsafe 0.18-2
+
*python2-pyqt4 4.10.3-1
+
*python2-sip 4.15.3-1
+
  
And lastly the QT packages
+
{| border="1"
*libdbusmenu-qt 0.9.2-2
+
|+ Tabular data
*phonon-qt4 4.7.0-2
+
|-
*polkit-qt 0.103.0-2
+
| alsa-lib || alsa-plugins
*poppler-qt4 0.24.4-1
+
|-
*pyqt4-common 4.10.3-1
+
| alsa-tools || alsa-utils
*python-pyqt4 4.10.3-1
+
|}
*python2-pyqt4 4.10.3-1
+
 
*qt4 4.8.5-6
+
 
 +
==== Install Bluez5 =====
 +
 
 +
Bluez5 is the latest bluetooth stack. Supposedly bluez5 unlike bluez4 requires pulseaudio to interface with wireless headsets. During testing this requirement seems true.
 +
 
 +
{| border="1"
 +
|+ Tabular data
 +
|-
 +
| bluez 5.11-1 || bluez-libs
 +
|-
 +
| bluez-utils ||
 +
|}
 +
 
 +
 
 +
===== Install Pulseaudio =====
 +
 
 +
Pulseaudio interfaces with ALSA, Bluez and other user mode programs. The pulseaudio package from AUR has capabilities not provided by the stock pulseaudio package which are required by Bluez.
 +
 
 +
{| border="1"
 +
|+ Tabular data
 +
|-
 +
| pulseaudio-git || libcanberra-pulse
 +
|}
 +
 
 +
===== Install Audacious =====
 +
Audacious is a program which plays audio files. It can work directly with ALSA or with Pulseaudio. Install audacious to test audio playback.
 +
 
 +
{| border="1"
 +
|+ Tabular data
 +
|-
 +
| audacious || audacious-plugins
 +
|}
 +
 
 +
==== Install Python and associated libraries ====
 +
 
 +
Audacious and the pulseaudio mixer pavucontrol require python and QT.
 +
 
 +
{| border="1"
 +
|+ Tabular data
 +
|-
 +
| python || python-dbus || python-dbus-common || python-lxml
 +
|-
 +
| python-lxml || python-pyqt4 || python-sip || python-xdg
 +
|-
 +
| python2 || python2-beaker || python2-cairo || python2-dbus
 +
|-
 +
| python2-gobject || python2-gobject2 || python2-mako || python2-markupsafe
 +
|-
 +
| python2-pyqt4 || python2-sip ||  ||
 +
|}
 +
 
 +
==== Install QT and associated libraries ====
 +
 
 +
QT provides GUI capabilities used by audacious and pulseaudio.
 +
 
 +
{| border="1"
 +
|+ Tabular data
 +
|-
 +
| libdbusmenu-qt || phonon-qt4 || polkit-qt || poppler-qt4
 +
|-
 +
| pyqt4-common || python-pyqt4 || python2-pyqt4 || qt4
 +
|}
 +
 
 +
 
 +
=== Procedure ===
 +
Once the required packages are installed, this procedure shows how to use the headset to play audio. The high level overview of the procedure is to pair the headset, connect the headset, configure the player and pulse audio controller and then play audio.
  
 
Start up a terminal and start the bluetooth service
 
Start up a terminal and start the bluetooth service

Revision as of 19:20, 7 December 2013

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary end Before you get started, you have to make sure that bluetooth is set up and working.

ALSA-BTSCO method

It is much easier to set up your bluetooth headset today, with bluez >= 3.16. You may want to try the out-of-box python script in this blog (you need edit the script to work with gconftool-2). There is also a piece of equivalent bash script here.

The following method is out-of-date and obsoleted.

NOTE: This method is also outdated as with newer versions of BlueZ. Anyone know what the exact version number when this stopped working is?

You need your headset's bdaddr. It is of the form 12:34:56:78:9A:BC. Either find it in the documentation of your headset, on the headset itself or with the hcitool scan command.

Install btscoAUR.

To load the kernel module, type:

# modprobe snd-bt-sco

There will now be an extra audio device. Use alsamixer -cN (where N is most likely 1) to set the volume. You can access the device with any alsa-capable application by choosing the device BT headset, or with any OSS application by using /dev/dspN as the audio device.

But to actually get any sound, you have to connect your headset to the computer first.

Connecting the headset

If you connect your headset for the first time, read the section about pairing first. To connect to your headset to the computer, use the command

$ btsco -f <bdaddr>

for example

$ btsco -f 12:34:56:78:9A:BC

Pairing the headset with your computer

The first time you connect the headset, you have to pair it with the computer. To do this, you need your headset's PIN. Depending on your headset you may have to reset the headset and repeat the pairing everytime you used the headset with another bluetooth device.

There are two ways to pair your headset with the computer:

Using bluez-gnome

Install the bluez-gnome package from the community repository. Then start the bt-applet program. Once you try to connect to the headset, a window will open and ask for the PIN.

Using passkey-agent

Before connecting to the headset, enter the command

$ passkey-agent --default <pin>

where <pin> is your headset's PIN. Then try to connect to the headset.

Headset and Alsa Devices

1. First if you have not already, install bluez from the official repositories. 2. Scan for your device

$ hcitool (-i <optional hci#>***) scan

3. Pair your headset with your device:

$ bluez-simple-agent (optional hci# ***) XX:XX:XX:XX:XX:XX
  and put in your pin (0000 or 1234, etc)

4. Make sure your /etc/bluetooth/audio.conf allows A2DP Audio Sinks. Place this line just bellow the [Genera] heading:

Enable=Source,Sink,Media,Socket

5. Add this to your /etc/asound.conf file:

#/etc/asound.conf

pcm.btheadset {
   type plug
   slave {
       pcm {
           type bluetooth
           device XX:XX:XX:XX:XX:XX 
           profile "auto"
       }   
   }   
   hint {
       show on
       description "BT Headset"
   }   
}
ctl.btheadset {
  type bluetooth
}  

6. Check to see if it has been added to alsa devices

$ aplay -L

7. Now play with aplay:

$ aplay -D btheadset /path/to/audio/file

or Mplayer:

$ mplayer -ao alsa:device=btheadset /path/to/audio/or/video/file
      • To find hci# for a usb dongle, type in
$ hcitool dev

Headset's multimedia buttons

In order to get your bluetooth headset's multimedia buttons (play, pause, next, previous) working you need to create /etc/modprobe.d/uinput.conf containing uinput.

PulseAudio method

This one`s much easier and more elegant. PulseAudio will seamlessly switch between output devices when the headset is turned on. If you have ALSA as the sound server, you need the following packages installed: pulseaudio and pulseaudio-alsa.

Now, to configure the audio output to use bluetooth, just install pavucontrol and run it to configure the audio output:

$ pavucontrol

See [this blog] for futher explanations. Make sure to take a look at the PulseAudio wiki entry for setting up PulseAudio, especially if you are running KDE.


Troubleshooting

Audio sink fails

Bluetooth headset is connected, but ALSA/PulseAudio fails to pick up the connected device. You will get "Audio sink fails". According to gentoo wiki, you have to verify than in /etc/bluetooth/audio.conf there is Enable=Socket under the [General] section heading.

Just do a # systemctl restart bluetooth to apply it.

Page timeout issue

If you receive this error whilst trying to pair your headset with your system using bluez-simple-agent, then you can try to restart your system and use the graphical bluez applet of your desktop environment.

ALSA, BLUEZ5, and PULSEAUDIO Method

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: Using first person, should use package templates, see Help:Style and related. (Discuss in Talk:Bluetooth headset#)

Bluez5, pulseaudio and ALSA work together to allow a wireless bluetooth headset to play audio. The following method works with a Lenovo T61p laptop and SoundBot SB220 wireless bluetooth headset. The required software stack is extensive and failure to include all components can produce errors which are difficult to understand. The following list of software might not be the minimum required set and needs to be examined more closely.

Install Software Packages

The core software components are ALSA, Bluez5, Pulseaudio. However there are additional libraries which are required. As well as a player which can play audio files. The following section lists the software packages installed in order to connect the headset and play audio over the headset.


Install Alsa and associated libraries.

ALSA works with the linux kernel to provide audio services to user mode software. The following packages are used.

Tabular data
alsa-lib alsa-plugins
alsa-tools alsa-utils


Install Bluez5 =

Bluez5 is the latest bluetooth stack. Supposedly bluez5 unlike bluez4 requires pulseaudio to interface with wireless headsets. During testing this requirement seems true.

Tabular data
bluez 5.11-1 bluez-libs
bluez-utils


Install Pulseaudio

Pulseaudio interfaces with ALSA, Bluez and other user mode programs. The pulseaudio package from AUR has capabilities not provided by the stock pulseaudio package which are required by Bluez.

Tabular data
pulseaudio-git libcanberra-pulse
Install Audacious

Audacious is a program which plays audio files. It can work directly with ALSA or with Pulseaudio. Install audacious to test audio playback.

Tabular data
audacious audacious-plugins

Install Python and associated libraries

Audacious and the pulseaudio mixer pavucontrol require python and QT.

Tabular data
python python-dbus python-dbus-common python-lxml
python-lxml python-pyqt4 python-sip python-xdg
python2 python2-beaker python2-cairo python2-dbus
python2-gobject python2-gobject2 python2-mako python2-markupsafe
python2-pyqt4 python2-sip

Install QT and associated libraries

QT provides GUI capabilities used by audacious and pulseaudio.

Tabular data
libdbusmenu-qt phonon-qt4 polkit-qt poppler-qt4
pyqt4-common python-pyqt4 python2-pyqt4 qt4


Procedure

Once the required packages are installed, this procedure shows how to use the headset to play audio. The high level overview of the procedure is to pair the headset, connect the headset, configure the player and pulse audio controller and then play audio.

Start up a terminal and start the bluetooth service

  1. systemctl start bluetooth

Start up another terminal in X and start the pulseaudio daemon. $ pulseaudio -D

Start up bluetoothctrl and pair and connect your headset

 $ bluetoothctl 
 [NEW] Controller 00:1E:4C:F4:98:5B t61p-0 [default]
 [NEW] Device 00:1A:7D:12:36:B9 SoundBot SB220
 [bluetooth]# show

<output omitted for bluetooth results>

 [bluetooth]# power on
 [bluetooth]# pairable on
 [bluetooth]# agent on
 [bluetooth]# default-agent
 [bluetooth]# scan on

<power on your headset in pairing mode. Eventually you will see what appears to be a mac address.>

 [bluetooth]# pair 00:1A:7D:12:36:B9
 [bluetooth]# connect 00:1A:7D:12:36:B9
 [bluetooth]# info 00:1A:7D:12:36:B9

Start up alsa, for simplicity unmute all your outputs. (Oddly enough some can be muted though. The ones I had muted during playback were):

  • Headphones
  • SPIDF

Start up audacious. Use the menu to select pulseaudio as your output. Somewhere I read that bluez5 requires pulseaudio-git and this jives with my experience.

Startup up pavucontrol in a terminal. In the Outputs tab select the bluetooth headset.

Switch between HSV and A2DP setting

This can easily be achieved by the following command where 2 needs to be changed with the correct device number.

pacmd set-card-profile 2 a2dp

A2DP not working with pulseaudio

If pulseaudio fails when changing the profile to A2DP with bluez 4.1+ and pulseaudio 3.0+, you can try disabling the Socket interface from /etc/bluetooth/audio.conf by removing the line Enable=Socket and adding line Disable=Socket

Disable=Socket

Tested Headsets

The following Bluetooth headsets have been tested with Arch Linux

  • Philips SHB9100 - Confirmed NOT TO WORK well. Have tried everything after a while they cut out. Pause and resume too is flakky and basically the whole wireless bluetooth experience is horrible. The following forum post[1] explains an underlying issue and describes a temporary solution which can be used to improve the audio quality pending a proper fix.
  • Parrot Zik - Confirmed to work out of the box with firmware 1.04! The MIC however is detected, but does not work at all. Sometimes it can lag behind (not stutter) but most of the times it is not noticeable unless you playing a game, in which case I would switch to wired which resolves the issue.
  • Sony DR-BT50 works for a2dp both with bluez4 and bluez5 (instructions here[2], subject to change)
  • SoundBot SB220 works with bluez5 and pulseaudio-git.

See also

Alternative method of connecting a BT headset to Linux:

Using the same device on Windows and Linux without pairing the device over and over again