HowTo: Use a Bluetooth headset with Ubuntu Hardy

Discussion in 'Other Operating Systems' started by HyRax1, Jul 6, 2008.

  1. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,712
    Location:
    At a desk. Distro:Ubuntu
    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! :p
     
    Last edited: May 13, 2009
  2. millermackj

    millermackj New Member

    Joined:
    Jul 9, 2008
    Messages:
    1
    how to disable automatic theme playing when headset is plugged in

    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
     
  3. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,712
    Location:
    At a desk. Distro:Ubuntu
    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.
     
  4. Outcast_Aussie

    Outcast_Aussie Member

    Joined:
    May 27, 2008
    Messages:
    773
    Location:
    Peterboro, Distro:Ubuntu
    This forum should have a +Rep facility.

    Thats a good "how to" dude.. Worthy of Rep
     
  5. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,712
    Location:
    At a desk. Distro:Ubuntu
    Cheers for that! Just glad to spread the knowledge. :)
     
  6. JWalshe

    JWalshe Member

    Joined:
    Jul 14, 2008
    Messages:
    2
    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
     
  7. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,712
    Location:
    At a desk. Distro:Ubuntu
    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?
     
  8. JWalshe

    JWalshe Member

    Joined:
    Jul 14, 2008
    Messages:
    2
    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
     
  9. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,712
    Location:
    At a desk. Distro:Ubuntu
    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.
     
  10. rever75

    rever75 New Member

    Joined:
    Jul 18, 2008
    Messages:
    2
    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.
     
  11. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,712
    Location:
    At a desk. Distro:Ubuntu
    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?
     
    Last edited: Jul 18, 2008
  12. rever75

    rever75 New Member

    Joined:
    Jul 18, 2008
    Messages:
    2
    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.
     
  13. ..:Be_Mons:..

    ..:Be_Mons:.. New Member

    Joined:
    Jul 10, 2008
    Messages:
    4
    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...
     
  14. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,712
    Location:
    At a desk. Distro:Ubuntu
    Do you hear the test audio through your headset in step 33?
     
  15. ..:Be_Mons:..

    ..:Be_Mons:.. New Member

    Joined:
    Jul 10, 2008
    Messages:
    4
    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....:rolleyes:
     
    Last edited: Jul 25, 2008
  16. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,712
    Location:
    At a desk. Distro:Ubuntu
    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!
     
  17. mfitzi

    mfitzi New Member

    Joined:
    Jul 27, 2008
    Messages:
    2
    Step 18

    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.

    The next command:
    mike@mike-desktop:~$ pactl load-module module-alsa-source device=bluetooth
    No valid command specified.

    Thank you, for the How To, they really help!!

    -Mike
     
  18. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,712
    Location:
    At a desk. Distro:Ubuntu
    That's OK - that's the purpose of the HowTo - to discover new and neat things! :)
    This is unusual as you should already have this command installed if you are using Ubuntu Hardy. Is that what you are using, or are you using a different distribution?
    Can you type in:
    Code:
    $ pactl load-module
    
    ...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.
     
  19. mfitzi

    mfitzi New Member

    Joined:
    Jul 27, 2008
    Messages:
    2
    Hello, and thank you for the reply!
    I am using Ubuntu 7.10 -Gutsy I believe.

    I ran the command "pactl load module" and received this as the output:
    "No valid command specified"

    -Mike
     
  20. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,712
    Location:
    At a desk. Distro:Ubuntu
    There's the problem then - Gutsy doesn't have PulseAudio installed as standard. Hardy does. :)

    I recommend you either upgrade to Hardy or install PulseAudio on your setup with these instructions.
     

Share This Page