51

I got the Sony MDR-ZN770BN connected to my PC via bluetooth. But I can only use A2DP. When I switch it to HSP, I get message "Failed to change profile to headset_head_unit", so no skype calls possible.

How can I solve that?

D. Joe
  • 511

5 Answers5

60

I had the similar problem on Ubuntu 18.04 with Galaxy Earbuds+ and here is how I solved it:

My earbuds profiles were A2DP, AVRCP and HFP and no support for HSP. Pulseaudio only supports HSP out-of-the-box. That's why I couldn't switch to HSP/HFP. In order to make HSP/HFP work, you have to enable HFP on pulseaudio which needs ofono.

  1. Install ofono:

    sudo apt install ofono
    
  2. Config pulseaudio to use ofono:

  • Goto /etc/pulse/default.pa find the line load-module module-bluetooth-discover and change it in load-module module-bluetooth-discover headset=ofono.

  • Add the user pulse to group bluetooth to grant the permission: sudo usermod -aG bluetooth pulse (probably it's already correct)

  • VERY IMPORTANT: To grant the permission, add this to /etc/dbus-1/system.d/ofono.conf (before </busconfig>):

      <policy user="pulse">
        <allow send_destination="org.ofono"/>
      </policy>
    
  1. Provide phonesim to ofono. In order to make ofono work, you have to provide a modem to it! You can install a modem emulator called phonesim (implemented by ofono) to make it work:
  • install ofono-phonesim (in some distros it is called phonesim). in Ubuntu 18.04 (for Ubuntu 20.04 follow this link):

     sudo apt install ofono-phonesim
    
  • Configure phonesim by adding the following lines to /etc/ofono/phonesim.conf:

      [phonesim]
      Driver=phonesim
      Address=127.0.0.1
      Port=12345
    
  • Restart ofono:

     sudo systemctl restart ofono.service
    
  • Start phonesim:

     ofono-phonesim -p 12345 /usr/share/phonesim/default.xml
    

Note that the command can be phonesim. To make sure phonesim is started correctly you can clone the ofono repo and use their test scripts:

cd /tmp
git clone git://git.kernel.org/pub/scm/network/ofono/ofono.git
cd ofono/test
./list-modems

You should see the modem in the result. You might have to first enable the modem by executing enable-modem and online-modem scripts in the same directory.

  • Once the modem is enabled, you should be able to enable HFP profile.
  1. Autostart phonesim. Since you have executed phonesim manually, after every restart you should execute it again. Instead you can install ofono-phonesim-autostart which will start the phonesim as a service.

References:

zx485
  • 2,426
  • 2
    This solved it for me with AirPods on Ubuntu 18.04 Thanks! – Christian Gill Jun 23 '20 at 16:26
  • Beautiful write up. Thanks a lot! I think you cna skip the Goto /etc/pulse/default.pa find the line load-module module-bluetooth-discover and change it in load-module module-bluetooth-discover headset=ofono. step, since PA in default mode will use either profiles. – Clément Jul 08 '20 at 15:49
  • 6
    I've never been so clueless when following orders, but it actually got my Huawei Freelace headphones to work! Thanks a lot. – iSWORD Sep 01 '20 at 14:44
  • This helped me with Ubuntu 18.04 for Airpods Pro! – Akhilesh Siddhanti Oct 10 '20 at 23:29
  • 4
    ofono-phonesim-autostart is not really working for me. How do I set it up? – Akhilesh Siddhanti Oct 10 '20 at 23:58
  • 3
    When I try to run ./enable-modem, I get the following error: File "/usr/lib/python3/dist-packages/dbus/connection.py", line 652, in call_blocking reply_message = self.send_message_with_reply_and_block( dbus.exceptions.DBusException: org.ofono.Error.Failed: Operation failed What does it mean and how do I get around it? – Zoltán Oct 13 '20 at 21:19
  • My problem with ./enable-modem was that I didn't have phonesim running while enabling the modem. The thing is that the previous command - ofono-phonesim -p 12345 /usr/share/phonesim/default.xml - has to be left running, then enable-modem works. – Zoltán Dec 18 '20 at 16:00
  • where is enable-modem located? – timekeeper Dec 20 '20 at 12:04
  • @timekeeper if you cloned the ofono git repository into tmp as described above, then it should be in the /tmp/ofono/test directory – Zoltán Dec 26 '20 at 17:18
  • @iSWORD I couldn't make my Huawei Freelace work with this method on Xubuntu 20.10. I also tried to restore my system back to 20.04 and tried again, but no luck. (Note: I didn't do "ofono-phonesim-autostart" step.) Can you help me on this? Share your steps maybe? – Eren Seymen Dec 31 '20 at 10:04
  • 3
    I had to use ./enable-modem /phonesim and ./online-modem /phonesim in order to earphones mic to work but output quality becomes terrible so I prefer using Internal Microfone Built-in and discard this solution. – Eduardo Feb 11 '21 at 21:56
  • How did you actually come up with all these steps? I mean, how did you even consider the "ofono" stuff to be needed? – mnj Feb 20 '21 at 09:24
  • 6
    feels like tutorial is incomplete by the end, the "ofono-phonesim -p 12345 /usr/share/phonesim/default.xml" , just hangs. Where to enable modem , which directory left to decide to the poor reader. Found 100 ofono polluted dirs. It is disgraceful to expect ubuntu to support airpods in 2021 out of the box. One day ... we say for last 30 years. Deleting all these voodoo packages and just accepting that i will have to switch to usb headphones to talk. – Aubergine Mar 09 '21 at 17:17
  • 1
    Running only ofono-phonesim -p 12345 /usr/share/phonesim/default.xml didn't work in my case, you also have to clone that git repo shared above and run ./enable-modem every time. That's how I got my Sony WH-XB900N headphones working but now there's some small but constant noise on my headphones, not sure why that would be but that's annoying as well. Anyway, thank you for the answer! At least I got them working finally. – Burak Kaymakci Mar 30 '21 at 15:01
  • It worked for me the first time I did it. Then tried to automate its start with the other answer you posted under this one and it hasn't worked again since then. – Fran Marzoa Apr 12 '21 at 19:41
  • 1
    Unfortunately it's not working for me. Everything seems to go as expected with creating the modem, starting it and checking it, but when I try to change the profile in blueman to Headset Head Unit (HSP/HFP) I get the error message Failed to change profile to headset_head_unit. – Andyc Apr 24 '21 at 01:17
  • I have successfully implemented the solution by concatenating the two answers of this topic but to make it work, every time the PC is restarted, I have to restart pulseaudio with "pulseaudio -k". How do I resolve? – Mario Palumbo Apr 30 '21 at 18:31
  • 1
    I could got it to work on Ubuntu 20.04 but it was very unstable, the source (Input) was changed after a couple of minutes in the middle of call. Worse than that, the ofonod suddenly gets somehow too busy and turns CPU up to 100% and i have to kill it… I'll undo everything and hope that a stable solution gets packed soon in the near future releases, not giving haters a chance to criticize the usability of Linux, anyhow TWS bluetooth devices are around since a couple of years! – roxch Jun 09 '21 at 15:04
  • Getting Unable to locate package ofono-phonesim when trying to install phonesim – backslashN Oct 14 '21 at 12:40
  • @backslashN there's a link to another question with new ppa for the package https://askubuntu.com/questions/1242450/when-will-add-ofono-phomesim-to-the-focal-repository-20-04 – culebrón Nov 01 '21 at 14:45
  • After several hours trying everything until find your tutorial. I can confirm it works with JBL LIVE650BTNC Headphone. Now I can use it as input source also (microphone as HFP). – marciowb Dec 07 '21 at 22:44
  • 1
    This tutorial does work, to be sure; but HFP will leave you with a very low quality sound input and even worse sound output. Not practical. – Shayan Feb 19 '22 at 13:12
49

I was facing the same issue with Oneplus Wireless Z Bass edition. My headset microphone was not detected by PulseAudio and the problem is that my headphones don't have HSP profile, only HFP profile. After trying for 2 days, I came to the solution of replacing PulseAudio with Pipewire sound server, which supports HSP, HFP and A2DP by itself. So there will be no need to install any other utility like ofono, phonesim. Also, to be noted that my problem wasn't resolved even after following all the steps to configure ofono in PulseAudio. So I came up with the steps to replace PulseAudio with PipeWire.

Here is the detailed article I have written to resolve this problem, the steps of which I'm also adding here. You can follow it and most probably be able to solve your problem.

Bluetooth headset microphone not detected

Open your terminal and follow these steps:

  1. We will use a PPA for adding Pipewire to Ubuntu 20.04, which is maintained regularly:

    sudo add-apt-repository ppa:pipewire-debian/pipewire-upstream
    
  2. To update the PPA packages in your system do:

    sudo apt update
    
  3. Install the package:

    sudo apt install pipewire
    
  4. There is also a dependency needed to be installed with Pipewire, otherwise you will face the issue of “Bluetooth headset won’t connect after installing pipewire”. Install the dependency by:

    sudo apt install libspa-0.2-bluetooth
    
  5. Now, to install the client libraries:

    sudo apt install pipewire-audio-client-libraries
    
  6. Reload the daemon:

    systemctl --user daemon-reload
    
  7. Disable PulseAudio:

    systemctl --user --now disable pulseaudio.service pulseaudio.socket
    
  8. If you are on Ubuntu 20.04, you also need to “mask” the PulseAudio by:

    systemctl --user mask pulseaudio
    

    I am not sure but, if possible, you can try to run this on other versions too.

  9. After a new update of Pipewire, you also need to enable pipewire-media-session-service:

    systemctl --user --now enable pipewire-media-session.service
    
  10. You can ensure that Pipewire is now running through:

    pactl info
    

    This command will give the following output, in Server Name you can see:

    PulseAudio (on PipeWire 0.3.28)
    

    Things should be working by now and you can see your microphone.


If it doesn’t show up, then try restarting Pipewire by this command:

systemctl --user restart pipewire

Also, you need to uninstall ofono and ofono-phonesim if you have them installed.

sudo apt remove ofono
sudo apt remove ofono-phonesim

If it’s still not showing your microphone, you can try rebooting once and remove and pair your Bluetooth device again to check if it works now.

I hope I have helped you solve your problem.

If you want to rollback all the changes we did, you can do it by using:

systemctl --user --now disable pipewire-media-session.service
systemctl --user unmask pulseaudio
systemctl --user --now enable pulseaudio.service pulseaudio.socket

Copied from comments, in case of the error "Connection failure: Connection refused":

do this step:

systemctl --user restart pipewire-pulse
ATEF
  • 117
1nfern0
  • 2,339
  • 2
    Thank you, this should be the accepted answer!! Just one thing, on your Medium post the hyphen autocorrect/formatting broke the systemctl commands, e.g. it looks like systemctl — user daemon-reload instead of systemctl --user daemon-reload – Constantinos Jun 01 '21 at 10:17
  • Thanks for your feedback! It really motivates me. Yes, even I saw this problem on Medium but couldn't fix the problem; that's why I posted steps separately. – 1nfern0 Jun 02 '21 at 05:36
  • Should be the accepted answer. – Marco M Jun 03 '21 at 17:35
  • Thanks a lot! Confirmed to work with Lenovo HT30. Using the previous approach with ofono did not lead me to any result – Shote Jun 10 '21 at 10:58
  • This also works with my JBL endurance headset, much simpler then the setup with ofono as well. – Jonathan Jun 23 '21 at 11:32
  • 1
    When running pactl info I get Connection failure: Connection refused. pa_context_connect() failed: Connection refused even after I restarted it. Any clue what this could mean? – Karussell Jul 14 '21 at 09:33
  • 6
    For connection fail: systemctl --user restart pipewire-pulse is missing after systemctl --user restart pipewire – Bernard Aug 09 '21 at 16:31
  • 3
    All works. but profiles HSP, HFP are absent – Andrey Nikishaev Sep 12 '21 at 11:05
  • I'm having the same issue as Andrey..... – user2279952 Oct 21 '21 at 07:01
  • Just as the prevous 2 commenters, this seems to have worked on Ubuntu 21.10, but audio profiles are again without input (Philips SHB3595 headset). Instead of A2DP + non-working HFP, I see A2DP, A2DP + some codec, A2DP + some codec XQ (extra quality?). In sound preferences, I see input methods: onboard microphone, monitor for built-in analog stero, monitor for Philips headset (which means what it plays, not the mic). – culebrón Nov 01 '21 at 15:32
  • Thanks man, haven't tried the solution yet, but i also have OnePlus Bullets Wireless Z bass edition and i had lost all hope for the mic to work finally seeing this is awesome. – Anantpatel Nov 08 '21 at 16:44
  • 2
    This should be the accepted answer, it worked great for me, on the contrary with the first answer... how is it that Ubuntu does not support Bluetooth Hear Phones by default as plug and play in 2021??? – JVGD Nov 10 '21 at 07:57
  • It works fine with OnePlus buds pro and Ubuntu 20.04 – mixalbl4 Apr 13 '22 at 06:47
  • I thought it wasn't working at all, because my Audacity kept seeing only the onboard microphone. But the last command (restart pipewire-pulse) saved it! Several years I wanted but couldn't use bluetooth headsets! Finally it works! – culebrón Jul 18 '22 at 19:26
  • This helped me to make work my airpods 3 clone's mic with ubuntu 20.04. Thanks – Bakhtiyor Sulaymonov Aug 13 '22 at 07:30
  • pactl info shows me Server Name: PulseAudio (on PipeWire 0.3.48), but still I get error when connecting my device through bluetoothctl: Failed to connect: org.bluez.Error.Failed br-connection-profile-unavailable. – mrpandey Nov 06 '22 at 12:41
16

I originally posted this as an edit to @alisabzevari's post, but the edit was rejected :( I still think the information is very valuable, and I wouldn't like to lose it, so I'm posting it as an answer:

As of 2020-10-17, in Ubuntu 20.04 ofono-phonesim-autostart is not available. What you could do is create the following systemd units to start it as a daemon on startup:

To run ofono-phonesim -p 12345 /usr/share/phonesim/default.xml on startup as a systemd unit, create the file /etc/systemd/system/ofono-phonesim.service (as root) with the following contents:

[Unit]
Description=Run ofono-phonesim in the background

[Service]
ExecStart=ofono-phonesim -p 12345 /usr/share/phonesim/default.xml Type=simple RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

After ofono-phonesim runs, you'll need to also enable and put the phonesim modem online. I (@Zoltán) did this by creating another systemd unit file that depends on the above ofono-phonesim systemd unit. Put the following contents in /etc/systemd/system/phonesim-enable-modem.service:

[Unit]
Description=Enable and online phonesim modem
Requires=ofono-phonesim.service

[Service] ExecStart=/<path-to-cloned-ofono-git-repo>/test/enable-modem /phonesim ExecStart=/<path-to-cloned-ofono-git-repo>/test/online-modem /phonesim Type=oneshot RemainAfterExit=yes

[Install] WantedBy=multi-user.target

Then run the following commands to run both daemons:

sudo systemctl daemon-reload

sudo systemctl enable ofono-phonesim.service sudo systemctl enable phonesim-enable-modem.service sudo service phonesim-enable-modem start

Check if the service is running with

sudo service phonesim-enable-modem status

Finally, restart pulseaudio with pulseaudio -k. Now you should be able to switch the profile to headset_head_unit.

Zoltán
  • 776
  • Thanks for writing this. I also don't know why your edit got rejected. StackExchange has some strict rules. – alisabzevari Dec 19 '20 at 19:28
  • 1
    Getting error when executing command sudo service phonesim-enable-modem.service start as Failed to start phonesim-enable-modem.service.service: Unit phonesim-enable-modem.service.service not found. – timekeeper Dec 20 '20 at 12:15
  • 1
    Before last command should be sudo service phonesim-enable-modem.service start – Andriy Slobodyanyk Dec 24 '20 at 09:58
  • Thanks @AndriySlobodyanyk, that's correct and I see your edit was already approved. – Zoltán Dec 26 '20 at 17:01
  • @timekeeper see Andriy's comment, there was an error in my post. – Zoltán Dec 26 '20 at 17:01
  • I have successfully implemented the solution by concatenating the two answers of this topic but to make it work, every time the PC is restarted, I have to restart pulseaudio with "pulseaudio -k". How do I resolve? – Mario Palumbo Apr 30 '21 at 17:07
  • Walked through it. ofono.service is running, ofono-phonesim too, phonesim-enable-modem started, but nothing changed. HFP audio profile still not working. :( – culebrón Nov 01 '21 at 15:36
4

I tried everything i possibly could, even the above answers. But i couldn't use the microphone of my headset. So i found another way to use a mic.

All you need is an Android phone which has bluetooth.

Firstly, go to google playstore on your phone and download a bluetooth microphone app.

I used this one (Simple Bluetooth Mic): https://play.google.com/store/apps/details?id=com.app.google.chrischan.simplebluetoothmic

Alternatively, you can use this: https://play.google.com/store/apps/details?id=wimlog.com.myandroidtest4.

Connect the phone's bluetooth to your PC.

Now connect your bluetooth headset to the PC. (Both the devices must be connected simultaneously)

Open the Simple Bluetooth Mic App on your phone, click on speak.

Voila, that's it.

Basically you are using your phone's mic, because we can't use the bluetooth headset for both audio input and output.(changing from A2DP to HSP everytime you need to use the headset mic is irritating af)

If this doesn't work, go to your sound settings and choose the input device as your phone's bluetooth.

HOPE THIS HELPS :)

2

Encountered this problem after some decent uptime (260 days or so), pulseaudio -k did not help, neither did switching audio profile to "off".

Restarting bluetooth (systemctl restart bluetooth) did.

ogurets
  • 141
  • restarting bluetooth service helped for me! thank you :-) I didn't attempt the solutions mentioned in the other answers. Just FYI – asgs Aug 21 '23 at 05:45
  • I'm glad I tried this first! This instantly fixed the problem. Thanks! – Jeff Lamb Sep 06 '23 at 17:08