Overclockers Australia Forums
OCAU News - Wiki - QuickLinks - Pix - Sponsors  

Go Back   Overclockers Australia Forums > Software Topics > Other Operating Systems

Notices


Sign up for a free OCAU account and this ad will go away!
Search our forums with Google:
Reply
 
Thread Tools
Old 6th July 2008, 10:21 AM   #1
HyRax1 Thread Starter
48656C6C6F20576F726C6421
 
HyRax1's Avatar
 
Join Date: Jun 2001
Location: At a desk. Distro:Ubuntu
Posts: 7,383
Lightbulb HowTo: Use a Bluetooth headset with Ubuntu Hardy

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.
  1. Fire up/install Ubuntu as normal.
  2. 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.
  3. 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.
  4. Get into a terminal.
  5. 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.
    .
  6. 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.
    .
  7. Near the top of the file you will see the following:
    Code:
    # HCId options
    options {
    	# Automatically initialize 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
    .
  8. A few lines beneath this is a section that reads as follows:
    Code:
    	# 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.
    .
  9. Save and exit.
  10. 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".
    .
  11. Turn on your Bluetooth headset, but don't go into pairing mode just yet.
  12. 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:
    Code:
    $ 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.
    .
  13. Highlight and copy the MAC address of the headset to the clipboard using your mouse and CTRL + SHIFT + C.
  14. 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.
    .
  15. In the text editor, type in the following, replacing the MAC address with the one you copied earlier (paste with CTRL + V):
    Code:
    pcm.bluetooth {
      type bluetooth
      device 00:33:44:DD:EE:FF
      profile "auto"
    }
    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".
    .
  16. Save and exit.
  17. Now type in:
    Code:
    $ sudo hciconfig hci0 voice 0x0060
    $ sudo modprobe snd_bt_sco
    $ sudo modprobe sco
    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).
    .
  18. Now we need to tell PulseAudio that your Bluetooth headset exists:
    Code:
    $ pactl load-module module-alsa-sink device=bluetooth
    $ pactl load-module module-alsa-source device=bluetooth
    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.
  19. 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".
  20. Now click on the Services tab and ensure Audio Service is enabled. If not, check the box and then close the window.
  21. Now type in:
    Code:
    $ sudo cat /proc/asound/cards
    ...and you should see output similar to the following:
    Code:
     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).
    .
  22. 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).
  23. 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.
    .
  24. 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.
    .
  25. Once installed, go to the System->Preferences->Sound. The Sound prefs window will appear.
  26. Under the Devices tab, change the "Sound playback" option for Sound Events, Music and Movies, and Audio Conferencing from "Autodetect" to "PulseAudio Sound Server".
  27. Click Close.
  28. 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.
  29. Now go to Applications->Sound & Video->PulseAudio Device Chooser. This will add a black microphone jack icon to your system tray.
  30. Do a left-click on the jack icon and a menu appears. In this menu, choose "Manager". A new window appears.
  31. 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.
  32. 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.
  33. 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).
  34. Close the PulseAudio Manager.
  35. Do another left-click on the mic jack icon in your system tray.
  36. Go to "Default Sink" and then choose "Other" from the sub-menu. A window appears.
  37. In this window, type in "alsa_output.bluetooth" and click OK.
  38. Play a sound from somewhere, eg: MP3 or movie in Totem. You should now hear your audio coming through your Bluetooth headset!
  39. 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.
  40. 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.
  41. Enjoy!
__________________
If practice makes perfect, and nobody's perfect, why practice?

Last edited by HyRax1; 13th May 2009 at 3:52 PM. Reason: Added disclaimer for Ubuntu Jaunty.
HyRax1 is offline   Reply With Quote

Join OCAU to remove this ad!
Old 9th July 2008, 8:39 PM   #2
millermackj
New Member
 
Join Date: Jul 2008
Posts: 1
Default how to disable automatic theme playing when headset is plugged in

Quote:
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!
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
millermackj is offline   Reply With Quote
Old 9th July 2008, 10:43 PM   #3
HyRax1 Thread Starter
48656C6C6F20576F726C6421
 
HyRax1's Avatar
 
Join Date: Jun 2001
Location: At a desk. Distro:Ubuntu
Posts: 7,383
Default

Quote:
Originally Posted by millermackj View Post
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
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.
__________________
If practice makes perfect, and nobody's perfect, why practice?
HyRax1 is offline   Reply With Quote
Old 9th July 2008, 11:28 PM   #4
Outcast_Aussie
Member
 
Join Date: May 2008
Location: Peterboro, Distro:Ubuntu
Posts: 622
Default

This forum should have a +Rep facility.

Thats a good "how to" dude.. Worthy of Rep
Outcast_Aussie is offline   Reply With Quote
Old 9th July 2008, 11:45 PM   #5
HyRax1 Thread Starter
48656C6C6F20576F726C6421
 
HyRax1's Avatar
 
Join Date: Jun 2001
Location: At a desk. Distro:Ubuntu
Posts: 7,383
Default

Quote:
Originally Posted by Outcast_Aussie View Post
This forum should have a +Rep facility.

Thats a good "how to" dude.. Worthy of Rep
Cheers for that! Just glad to spread the knowledge.
__________________
If practice makes perfect, and nobody's perfect, why practice?
HyRax1 is offline   Reply With Quote
Old 14th July 2008, 10:36 PM   #6
JWalshe
Member
 
Join Date: Jul 2008
Posts: 2
Default channels count not available error

Hi guys,
I have been following this how-to with great success until step 23 where we play a sample file. I get the following error

john@john-laptop-Ubuntu:~$ aplay -D bluetooth -f s16_le /usr/share/sounds/login.wav
Playing WAVE '/usr/share/sounds/login.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
aplay: set_params:906: Channels count non available

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.

Le meas, John
JWalshe is offline   Reply With Quote
Old 14th July 2008, 10:41 PM   #7
HyRax1 Thread Starter
48656C6C6F20576F726C6421
 
HyRax1's Avatar
 
Join Date: Jun 2001
Location: At a desk. Distro:Ubuntu
Posts: 7,383
Default

That error comes up when there's an issue with more than one sound interface on the system (which technically you have in this instance).

Does the sound play through your speakers if you specify "default" instead of "bluetooth" in the aplay command?

If it does, then double-check that the headset is paired properly. Did Ubuntu prompt you for the headset's PIN to connect?
__________________
If practice makes perfect, and nobody's perfect, why practice?
HyRax1 is offline   Reply With Quote
Old 14th July 2008, 11:39 PM   #8
JWalshe
Member
 
Join Date: Jul 2008
Posts: 2
Default

Hi HyRax1,
Thanks for the quick reply.

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.

John
JWalshe is offline   Reply With Quote
Old 15th July 2008, 5:49 AM   #9
HyRax1 Thread Starter
48656C6C6F20576F726C6421
 
HyRax1's Avatar
 
Join Date: Jun 2001
Location: At a desk. Distro:Ubuntu
Posts: 7,383
Default

Try:
  1. Deleting the pairing by doing a right-click on the Bluetooth icon in the system tray. In the Preferences tab you should see the device listed. Click it and then click Delete.
  2. Reboot just to ensure everything is clean and unloaded.
  3. Double-check that the .asoundrc file is 100% correct, especially the MAC address.
  4. Pair the headset again by issuing the aplay command again - you will be re-prompted for the PIN.
  5. Issue the pactl commands again - this will initialise the headset for PulseAudio causing it to beep as you heard previously.
  6. Continue with PulseAudio Manager configuration.
If you still have issues, try this:
  1. Open a terminal and type in:
    Code:
    $ sudo gedit /etc/rc.local
  2. Scroll to the end of the file and insert a line just before "exit 0" and put this in:
    Code:
    hciconfig hci0 inqmode 0
  3. Save and reboot. This line will correct a minor bug in Bluetooth that normally only affects file transfers in terms of "finding a device" to transfer to, but who knows - it may help you out here.
  4. Re-pair and try aplay again.
__________________
If practice makes perfect, and nobody's perfect, why practice?
HyRax1 is offline   Reply With Quote
Old 17th July 2008, 11:40 PM   #10
rever75
New Member
 
Join Date: Jul 2008
Posts: 2
Default

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.
rever75 is offline   Reply With Quote
Old 18th July 2008, 5:51 AM   #11
HyRax1 Thread Starter
48656C6C6F20576F726C6421
 
HyRax1's Avatar
 
Join Date: Jun 2001
Location: At a desk. Distro:Ubuntu
Posts: 7,383
Default

Quote:
Originally Posted by rever75 View Post
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.
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?
__________________
If practice makes perfect, and nobody's perfect, why practice?

Last edited by HyRax1; 18th July 2008 at 6:32 AM. Reason: Research on the problem.
HyRax1 is offline   Reply With Quote
Old 18th July 2008, 11:33 PM   #12
rever75
New Member
 
Join Date: Jul 2008
Posts: 2
Default

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.
rever75 is offline   Reply With Quote
Old 24th July 2008, 1:54 PM   #13
..:Be_Mons:..
New Member
 
Join Date: Jul 2008
Posts: 4
Default

Hi HyRax1

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...
..:Be_Mons:.. is offline   Reply With Quote
Old 24th July 2008, 2:28 PM   #14
HyRax1 Thread Starter
48656C6C6F20576F726C6421
 
HyRax1's Avatar
 
Join Date: Jun 2001
Location: At a desk. Distro:Ubuntu
Posts: 7,383
Default

Quote:
Originally Posted by ..:Be_Mons:.. View Post
Hi HyRax1

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...
Do you hear the test audio through your headset in step 33?
__________________
If practice makes perfect, and nobody's perfect, why practice?
HyRax1 is offline   Reply With Quote
Old 25th July 2008, 5:14 AM   #15
..:Be_Mons:..
New Member
 
Join Date: Jul 2008
Posts: 4
Default

Quote:
Originally Posted by HyRax1 View Post
Do you hear the test audio through your headset in step 33?
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....

Last edited by ..:Be_Mons:..; 25th July 2008 at 5:26 AM.
..:Be_Mons:.. is offline   Reply With Quote
Reply

Bookmarks

Tags
audio, bluetooth, guide, hardy, howto, ubuntu

Sign up for a free OCAU account and this ad will go away!

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +10. The time now is 11:24 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd. -
OCAU is not responsible for the content of individual messages posted by others.
Other content copyright Overclockers Australia.
OCAU is hosted by Internode!