个人工具

UbuntuHelp:BluetoothHeadset

来自Ubuntu中文

Wikibot讨论 | 贡献2009年5月12日 (二) 16:02的版本

跳转至: 导航, 搜索

<<Include(Tag/ContentCleanup)>> Stolen from HyRax1 on the Overclockers forum. Don't forget to send him a nice thank you note for this.

Purpose

This guide should help you redirect music, audio and media players to your Bluetooth headset. To make this work properly, all audio will have to be redirected through the PulseAudio Server

Prerequisites

  • Bluetooth interface to your PC
  • Ubuntu Hardy
  • Internet access or other such access to the Ubuntu repositories to install extra software from
  • Suitable Bluetooth headset. Should support Bluetooth 1.2 and 2.0, and the headset, handsfree A2DP and AVRCP profiles (typical function set of any headset/handsfree unit these days)

Instructions

These instructions should be adaptable to other distributions.

  1. 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.
  2. 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.
  3. Open a terminal window
  4. Verify that your Bluetooth adapter is running with:
hciconfig -a
  

If you get details about hci0 listed including manufacturer's name, then your adapter is working. You should see the second line with

UP RUNNING PSCAN
  

If not then run

sudo hciconfig hci0 reset
  
  1. Type in the following to edit your Bluetooth configuration file:
sudo gedit /etc/bluetooth/hcid.conf
  

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

  1. Change the following:
  • security user line to read security auto
  • passkey “1234” to passkey “0000”
  1. Save and exit
  2. Restart Bluetooth by typing the following into the Terminal window:
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 E.g.: If your PC's name is gordon, the message would say gordon-0 Device has been made connectable

  1. Turn on your Bluetooth headset, but don't go into pairing mode just yet

10. Scan for Bluetooth devices by typing the following into a terminal:

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:

$ 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. 11. Copy the MAC address of the headset. Then type into a Terminal window:

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. 12. In the text editor, type in the following, replacing the MAC address with the one you copied earlier:

pcm.bluetooth {
	type bluetooth
	device 00:33:44:DD:EE:FF
	profile “auto”
}
  

13. Save and exit 14. Enable sound drivers by typing the following into a terminal:

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). Save and exit. 15. Now we need to tell PulseAudio that your Bluetooth headset exists by running the following commands in a terminal:

pactl load-module module-alsa-sink device=bluetooth
pactl load-module module-alsa-source device=bluetooth
  

This is only temporary. Make an executable script to run just after you pair your Bluetooth headset by copying the previous commands into a text file and saving it with executable permissions. Right mouse click on the Bluetooth icon in your system tray and choose Preferences, select the Services tab and ensure Audio Service is enabled. If not, check the box and then close the window. BluetoothPulseaudioTroubleshooting 16. Check soundcards by typing the following into a terminal:

sudo cat /proc/asound/cards
  

You should see similar output:

 0 [I82801DBICH4   	]: ICH4 - Intel 82801DB-ICH4

                      		   Intel 82801DB-ICH4 with STAC9750,51 at irq 5

 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). 17. Switch your headset into pairing mode (refer to your headset's manual) Use this command to force pairing;

gconftool -t string -s /system/gstreamer/0.10/default/musicaudiosink "alsasink device=bluetooth" 
  

You will need to enter the code (0000) twice. Check for bonded devices in the bluetooth applet preferences. Use this to repair your audio;

gconftool -t string -s /system/gstreamer/0.10/default/musicaudiosink "autoaudiosink"
  

18. Play a test sound by typing the following into a terminal:

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

This will attempt direct communication with your headset and you should hear the familiar Ubuntu login sound play through your headset. 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. 19. Install new PulseAudio-related software by typing the following in a terminal:

sudo apt-get install paprefs paman padevchooser
  

20. Switch to PulseAudio by going into System | Preferences | Sound. Go into the Devices tab and change the Sound playback option for everything from Autodetect to PulseAudio Sound Server. Close 21. Test the PulseAudio sound by playing an MP3 or video or anything. This confirms that PulseAudio is working in general. 22. Open the PulseAudio Device Chooser by going to Applications | Sound & Video | PulseAudio Device Chooser. This will add a black microphone jack icon to your system tray 23. Open the PulseAudio Manager by left-clicking on the jack icon and choosing Manager. If not already connected, click on the Connect button. 24. Check the Devices tab and under Sinks you should see an entry for alsa_output.bluetoot. 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) 25. Close the PulseAudio Manager 26. Do another left-click on the mic jack icon in your system tray and go to Default Sink and then choose Other from the sub-menu. In the new window that opens type in:

alsa_output.bluetooth
  

Click OK 27. Test the redirection by playing an MP3 or video or anything. You should now hear sound from your Bluetooth headset. 28. Switch back to your speakers by left-clicking on the mic jack icon in your system tray and go to Default Sink and then choose Default