HowTo: Use a Bluetooth headset with Ubuntu Hardy
Recently I went and bought myself a cheap Bluetooth stereo headset for using with my Nokia N95 to make calls and listen to music and it occurred to me that I could also use it to listen to music from my Ubuntu desktop, so here’s a HowTo on how to hook it up to Ubuntu and redirect your music and media players to it.
This guide is based on the guides at Ubuntu Forums with some modifications to be more step-explicit and thus newbie-friendly. This is a re-post of my guide from Overclockers Australia with updates and screenshots.
Purpose: To play your audio such as MP3′s and movie output through a Bluetooth-connected audio headset.
Scenario: You are too lazy to plug in a cable to your PC. You want to walk around your house without a long cable after you. You want to look cool to your mates. You want to psyche out your non-tech parents by listening to music without any audio device or cables attached to you. Problem is, very few Linux apps have direct support for directing sound to any other device.
Solution: Redirect all audio using the PulseAudio Server on Ubuntu Hardy.
Prerequisites:
- Bluetooth interface to your PC. This can be inbuilt, such as on a modern notebook PC, or a USB dongle such as the one I use. Your adapter must support Bluetooth 1.2 or higher.
- Ubuntu Hardy 8.04 (I’m using 8.04.1 64-bit in this example).
- Internet access or other such access to the Ubuntu repositories to install extra software from.
- Suitable Bluetooth headset. The unit I bought is a TDK BT100 pair of buds. Supports Bluetooth 1.2 and 2.0, does headset, handsfree A2DP and AVRCP functions (typical function set of any headset/handsfree unit these days). Though the sound quality of these things isn’t that great, it was only $49 at my local PC shop. You can get cheaper units through sites such as Catch of the Day
Pros:
- You are cable free! You can walk around the house (as far as the range of your Bluetooth adapter goes) and listen to music/movies.
- If your headset also has a mic, you can use that too for VOIP apps and the like.
Cons:
- A Bluetooth headset is generally more expensive than a cabled one.
- Most headset batteries only last four hours in continuous use before needing a recharge (though the TDK unit I have plugs into mini-USB to recharge and can still be used whilst recharging, which is convenient).
- Audio quality is generally not as good as a dedicated cabled headset.
- For those headsets that have battery-saving functions when idle, some are known to clip the start of the audio playback when turning back on (my set causes Ubuntu to wait until it’s up and running before streaming the audio, thus no clipping).
- There are some known issues with using this method with 32-bit Skype under 64-bit Ubuntu, which I won’t go into detail here (since I don’t use Skype). Refer to the Ubuntu Forums for more details about it.
- At least on my headset, there is an ever-so-slight delay in audio sync when watching video.
These instructions should be adaptable to other distributions.
- Fire up/install Ubuntu as normal.
- Plug in or enable your Bluetooth adapter. Your Bluetooth adapter will be automatically detected and drivers loaded – there is nothing for you to do manually here.
- If you have NEVER used Bluetooth on your Ubuntu setup before, then go to the next step, otherwise skip to Step 11 because you’re probably already setup properly.
- Get into a terminal.
- Verify that your Bluetooth adapter is running with:
$ hciconfig -aIf you get details about hci0 listed including manufacturer’s name, then your adapter is working.
- Type in the following to edit your Bluetooth configuration file:
$ sudo gedit /etc/bluetooth/hcid.confThis will bring up the Bluetooth configuration into the GEdit text editor.
- Near the top of the file you will see the following:
# HCId options options { # Automatically initialise new devices autoinit yes; # Security Manager mode # none - Security manager disabled # auto - Use local PIN for incoming connections # user - Always ask user for a PIN # security user;
Change the security user line to security auto
- A few lines beneath this is a section that reads as follows:
# Default PIN code for incoming connections passkey "1234";Change the 1234 to something else, eg: 4493. This is the pin number required for other Bluetooth devices to connect to you and it would be insecure to leave it at the default.
- Save and exit.
- Now restart Bluetooth by typing in:
$ sudo /etc/init.d/bluetooth restartWhen you do this, an informational bubble will appear in your task bar saying <hostname>-0 Device has been made connectable, eg: if your PC’s name is “gordon”, the message would say “gordon-0 Device has been made connectable”.
- Turn on your Bluetooth headset, but don’t go into pairing mode just yet.
- In your terminal, type in the following:
$ hcitool scanYour PC will now scan for local Bluetooth devices and your headset should appear in the resulting list after a few seconds (along with anyone’s Bluetooth-enabled mobile phones that are in range). The output will look something like:
$ hcitool scan Scanning ... 00:11:22:AA:BB:CC Nokia N95 00:33:44:DD:EE:FF BT81 $In this example, my PC has found my Nokia mobile phone and my Bluetooth headset and shown me the MAC addresses for both of them.
NOTE: If your headset does NOT appear, you probably already have it paired with something else, like your mobile phone. In this case, switch the headset to pairing mode and then run the scan again.
- Highlight and copy the MAC address of the headset to the clipboard using your mouse and CTRL + SHIFT + C.
- Now type in:
$ gedit ~/.asoundrcNote the period before “asoundrc”. This will create a new hidden text file called .asoundrc in the root of your Home directory and open GEdit so you can add to it. The file is hidden because of the leading period.
- In the text editor, type in the following, replacing the MAC address with the one you copied earlier (paste with CTRL + V):
pcm.btheadset { type bluetooth device 00:33:44:DD:EE:FF profile "auto" }NOTE: In this example, I am naming the device “btheadset”. Yopu can put anything you like here, but avoid using just the word “bluetooth” as depending on your distro, you may find that word is reserved.
- Save and exit.
- Now type in:
$ sudo hciconfig hci0 voice 0x0060 $ sudo modprobe snd_bt_sco $ sudo modprobe sco
This will enable the sound transport on your Bluetooth adapter and load the modules necessary to carry Bluetooth audio. Note that the two modprobe lines will only enable Bluetooth audio temporarily until you reboot. If you would like to load the drivers automatically on each boot, we need to add the modules to the /etc/modules file as follows:
$ sudo gedit /etc/modulesScroll right to the bottom and add the following two lines right on the end:
snd_bt_sco scoSave & exit.
- Now we need to tell PulseAudio that your Bluetooth headset exists:
$ pactl load-module module-alsa-sink device=btheadset $ pactl load-module module-alsa-source device=btheadsetAgain this enables your Bluetooth headset for PulseAudio only temporarily. To enable it permanently, we would normally create a new file using gedit ~/.pulse/default.pa and paste the two lines above into it and then save, however I’ve found that this tends to break PulseAudio because the bonding of your headset needs to have occured before issuing the above commands, or PulseAudio refuses to start upon reboot. To keep using your Bluetooth headset, you need to execute these commands manually after booting up and pairing. Probably the easiest is to knock up a quick shell script as follows:
$ gedit "~/Desktop/Setup my headset.sh"…and in the blank text editor, type in the following:
#!/bin/bash $ pactl load-module module-alsa-sink device=btheadset $ pactl load-module module-alsa-source device=btheadset
Save it, exit and then make it executable with:
$ chmod a+x "~/Desktop/Setup my headset.sh"Now you can double-click it on the desktop.
- We’re almost ready to pair with the headset and hear some basic audio, but before we do that, do a right-mouse click on the Bluetooth icon in your system tray and choose “Preferences”.
- Now click on the Services tab and ensure Audio Service is enabled. If not, check the box and then close the window.
- Now type in:
$ cat /proc/asound/cards…and you should see output similar to the following:
0 [Intel ]: HDA-Intel - HDA Intel HDA Intel at 0xea400000 irq 22 1 [Headset ]: Bluetooth SCO - BT Headset BT Headset 1
This shows us that the system is ready to use the Bluetooth headset as device 1 (but we haven’t paired it yet, so technically it won’t be able to use it just yet).
- The best way to trigger a pairing is to provoke the unit into a response as the normal methods don’t always work. Switch your headset into pairing mode (refer to your headset’s manual).
- While the headset it in pairing mode, type in the following:
$ aplay -D btheadset -f s16_le /usr/share/sounds/login.wavThis will attempt direct communication with your headset, and within a second or so, an information bubble will appear under the Bluetooth icon in the system tray asking you for the PIN number to access the headset.
- Click on the “Enter passkey” button to enter the PIN and then type it in. For most headsets, the PIN is 0000, but refer to your headset’s manual.
Ubuntu should soon after confirm that it has “bonded” with the headset and you should suddenly hear the familiar Ubuntu login sound play through your headset! Hooray! We have sound!
Unfortunately only Aplay will play anything through your headset. All other sounds are still coming through your speakers. Unless the application in question can redirect audio to another detected device, it will always play through the standard-out, so applications such as Totem and Rhythmbox will still output via your speakers and not give a hoot about your Bluetooth headset. To fix this, we need to make use of the PulseAudio Server which can redirect output to another device.
- The PulseAudio Server is already installed by default in Ubuntu Hardy, so we just need to install some tools to manipulate it. Go back to your terminal and type in the following:
$ sudo apt-get install paprefs paman padevchooserThis will install the PulseAudio Preferences GUI app, the PulseAudio Manager GUI app and the PulseAudio Device Chooser GUI app.
- Go to Applications->Sound & Video->PulseAudio Device Chooser. This will add a black microphone jack icon to your system tray.
- Do a left-click on the jack icon and a menu appears. In this menu, choose “Manager”. A new window appears.
- If it’s not already connected, click on the “Connect” button to connect to your local PulseAudio server. When connected, you will see details about it listed.
- Click on the Devices tab. Under “Sinks” you should see an entry for “alsa_output.btheadset”. This is picked up directly from your ~/.asoundrc file.
- Now go to the Sample Cache tab. At the bottom is a “Playback on” drop-down. Choose alsa_output.btheadset from this list and click on the Play button. You should hear the Ubuntu login sound through your headset. This proves to us that PulseAudio can play through your Bluetooth headset (but this is NOT the redirection – this is just a test).
- Close the PulseAudio Manager.
- Do another left-click on the mic jack icon in your system tray.
- Go to “Default Sink” and then choose “Other” from the sub-menu. A window appears.
- In this window, type in “alsa_output.bluetooth” and click OK.
- Play a sound from somewhere, eg: MP3 or movie in Totem. You should now hear your audio coming through your Bluetooth headset!
- To switch back to your speakers, simply click on the mic jack icon again, choose “Default Sink” and choose “Default” from the sub-menu. The next audio stream played will go back through your speakers.
- To make the PulseAudio Device Chooser start automatically on startup, click on the mic jack icon again, choose Preferences from the menu and then click on “Start applet on Session Login” in the window.
- Enjoy!












Fantastic guide man, you rock!!!