NOTE:This instruction does not work with Ubuntu Jaunty 9.04. Please refer to this guide for connecting your Bluetooth headset with Jaunty.

Just bought myself a cheap Bluetooth headset, 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.

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.

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:

Code:

$ hciconfig -a

If 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:

Code:

$ sudo gedit /etc/bluetooth/hcid.conf

This will bring up the Bluetooth configuration into the GEdit text editor.
.

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:

Code:

$ sudo /etc/init.d/bluetooth restart

When 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:

Code:

$ hcitool scan

Your 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:

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:

Code:

sudo gedit ~/.asoundrc

Note 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):

NOTE: Depending on your distro, you may find that the word "Bluetooth" is reserved. If, when you get to Step 23, you hear anything BUT the audio you are playing, change the "pcm.bluetooth" bit above into something else, eg: "pcm.btheadset" and try your audio again. Remember then to change every typed reference in this guide from "bluetooth" to "btheadset".
.

This will enable sound on your 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, only add the two modprobe lines above to the end of the /etc/modules file (sudo gedit /etc/modules).
.

Note that this enables your Bluetooth headset for PulseAudio only temporarily. To enable it permanently, create a new file using gedit ~/.pulse/default.pa and paste the two lines above into it and then save. NOTE: I've just noticed 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. Don't create this file (or delete/rename if you've already created it) and PulseAudio works fine again. To keep using your Bluetooth headset, move the file you created to your Desktop and make it executable. Once your Desktop has loaded and you've paired your headset, then execute the file by double-clicking on it to notify PulseAudio about the headset.

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.

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:

Code:

$ aplay -D bluetooth -f s16_le /usr/share/sounds/login.wav

This 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 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:

Code:

$ sudo apt-get install paprefs paman padevchooser

This will install the PulseAudio Preferences app, the PulseAudio Manager app and the PulseAudio Device Chooser app.
.

Once installed, go to the System->Preferences->Sound. The Sound prefs window will appear.

Under the Devices tab, change the "Sound playback" option for Sound Events, Music and Movies, and Audio Conferencing from "Autodetect" to "PulseAudio Sound Server".

Click Close.

Play something, be it an MP3 or video to ensure that your audio still works in general through your speakers. This confirms PulseAudio is working in general.

Now 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.bluetooth". 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 Bluetooth from this list and click on the Play button. You should hear the Ubuntu login sound through your speakers. 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.

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!

Click to expand...

Hello.
thank you for this detailed how-to. I am curious if you or any other readers know how to disable this login sound from playing from the newly plugged in or "bonded" headset. I have all of my system sounds set to 'none' but apparently that is irrelevant. any info would be appreciated.
thanks again,
jacob

Hello.
thank you for this detailed how-to. I am curious if you or any other readers know how to disable this login sound from playing from the newly plugged in or "bonded" headset. I have all of my system sounds set to 'none' but apparently that is irrelevant. any info would be appreciated.
thanks again,
jacob

Click to expand...

The login sound is facilitated by the path of the file to play. The "aplay" app just plays any wave file you throw at it. In my example, I just chose the login sound because everyone is familiar with it. You can change it something else if you like - it's just there to prove that a sound can be played. Eg:

Code:

$ aplay -D bluetooth -f s16_le /usr/share/sounds/question.wav

...will play the little drum ditty that plays when Ubuntu is ready for login. Have a look at the /usr/share/sounds directory for the other sounds that Ubuntu comes with.

Now, if you're referring to the login sound that plays when you plug in a USB headset or similar, then I can't say I've ever been bothered by it (personally I think it's cool), so I don't know if there's a config file somewhere to change this, but you could always rename the login.wav file to something else so that it cannot be found to play in the first place.

I google this error but didn't get any information that was clear enough/relevant to this particular scenario.

Now I do have to admit that I am new to Linux and this is my first sortie into using this OS. The pc (Dell Inspiron 1150)has a virgin Ubuntu (Hardy Heron) installation, a Belkin F8T012 dongle and the headset is a Plantronics 520.

Can anyone give me any pointers/recommendations for follow to get past the above error.

The sound does play to the speakers when I use "default" instead of "bluetooth".
The headset appears to be paired ok, in that when I turn the headset on I'm prompted to grant authorisation, to which I reply yes. It would appear that the pc must have the passkey stored somewhere. I tried to disconnect so that I could go through the passkey setup again but I never get that step again.

Also when I have the headset on and I run the pactl cmds in step 18, the headset makes some beeps.

I did proceed to load the Pulse audio device chooser stuff and it all appears to run ok with the default sound card, but still nothing from the bluetooth.

I have followed your instructions which were great. However, all I get when trying to play sounds is crackle noises. This is on a Dell HCB29 headset.

Click to expand...

Crackling? Hmmm... Does the headset work properly with any other device, eg: your mobile phone?

EDIT: Googling around, there seems to be others having similar crackling issues with Dell-branded Bluetooth devices, and its not necessarily to do with the headset itself either. What Bluetooth dongle/device are you using?

The computer I am running on is a Dell Vosto 1700 with a built in Broadcom bluetooth adaptor. Everything works fine in Skype as far as talking and listening. However, Skype is not using Pulse Audio as far as I know. When I try to listen to Music or anything in Pulse Audio I get the noise. Thanks for any help you mat provide, this was a great tutorial.

I really apreciate this thread, it helps me to understand the way that bluetooth works, but... XD, i have a strange issue, i really follow all the steps, but when i try to play a sound in a Sample Cache, like gnome star, select Play_Back on: alsa_output.bluetooth i just hear a noise "ssssssssss", the same case for ever sound that i send to this device (selected in Volume Manager), in the step 23, i can hear the file correctly, even if i ignore the PA, and i configure i.e. the amarok to work with alsa and put the bluetooth for output device works fine. Thanks in advance if you can give me some ideas for correct the problem...

I really apreciate this thread, it helps me to understand the way that bluetooth works, but... XD, i have a strange issue, i really follow all the steps, but when i try to play a sound in a Sample Cache, like gnome star, select Play_Back on: alsa_output.bluetooth i just hear a noise "ssssssssss", the same case for ever sound that i send to this device (selected in Volume Manager), in the step 23, i can hear the file correctly, even if i ignore the PA, and i configure i.e. the amarok to work with alsa and put the bluetooth for output device works fine. Thanks in advance if you can give me some ideas for correct the problem...

I just hear noise through my headset , but in step 23 i hear the sound fine, I'm trying to find some suspicious on the system logs....

Click to expand...

Looking around is seems others are having similar problems, but there is no definitive remedy to the situation yet - it appears to be random to the point that no clear-cut notion of hardware incompatibility can be ascertained. In some cases, the noise comes through people's main speakers, not headsets.

PulseAudio is still fairly new and there are a handful of known bugs with it. For example, I've given up trying to get PA working on this one laptop I have simply because when active, it grinds the response of the system down and makes it sluggish, yet the same setup on a desktop PC works perfectly.

All I can say at this stage is that if you have access to another Bluetooth audio device, try it out and see if you get the same noise problem, otherwise the only suggestion I can make is to ensure that you haven't got too many audio sources running at once (apparently Flash can run amok with sound, generating too many sources at once when it should be generating less) - there is a general consensus in things I Googled up that suggest that giving PA too much to do at once can cause it to hiccup a bit, but of course that doesn't explain why you can hear Aplay through your headset and not PulseAudio.

See if the logs reveal anything obvious, but I'm afraid that's all I can suggest as I'm not experiencing any issues with my headset at all!

Hello,
I was following along flawlessly, until step 18.
Please bear with me, as I am VERY new to Linux.

When I type in the 1st command, I received:
mike@mike-desktop:~$ pactl load-module-alsa-sink device=bluetooth
The program 'pactl' is currently not installed. You can install it by typing:
sudo apt-get install pulseaudio-utils

Which I did, then I get the following after install...
mike@mike-desktop:~$ pactl load-module-alsa-sink device=bluetooth
No valid command specified.

...and see if you get the error "You have to specify a module name and arguments."? If so, then try:

Code:

$ pactl load-module module-alsa-source

...and see if you get a number returned. If it fails here, then for some reason you do not have Alsa sources available to you - if you're not using Ubuntu, then it's possible you don't have PulseAudio fully installed or installed at all, hence the missing modules.