How to transfer a bluetooth headset microphone from Debian 11 to Home Assistant Rhasspy Assistant?

How to transfer a bluetooth headset microphone from Debian 11 to Home Assistant, in the Rhasspy Assistant addon. There is a bluetooth headset with a microphone. Home Assistant is installed on Debian 11, on a Beelink U59 Pro mini PC, which has built-in bluetooth. In Debian 11, the bluetooth headset works properly, plays sound and records from the microphone, but in the Home Assistant, the microphone does not work, only the sound works. I need a microphone for Rhasspy Assistant so that I can connect a bluetooth speaker with a microphone and control the smart home by voice, but unfortunately the microphone does not want to work in Rhasspy Assistant.

What have I done?

Brought out the available sound cards with the command

pacmd list-cards

Displayed the available active profiles with the command

pacmd list-cards | grep 'active profile'

Further, knowing the bluetooth headset profile, I assigned an active profile for the bluetooth headset, after checking with the command

pacmd set-card-profile bluez_card.54_42_49_A5_56_AB headset_head_unit

After it worked, I added the code to `/etc/pulse/default.pa’. I found the answer here

.ifexists bluez_card.54_42_49_A5_56_AB
pactl set-card-profile bluez_card.54_42_49_A5_56_AB headset_head_unit
.endif

I tried to assign an input for the microphone in order to transfer it to the Home Assistant, but it didn’t work out for me

pactl set-sink-port bluez_sink.54_42_49_A5_56_AB.headset_head_unit handsfree-input

Microphone recording works in Debian 11. Checking the recording from the microphone. The command to record from the microphone.

arecord -d 5 test_record.wav

5 - recording time in seconds, you can specify any number of seconds
test_record - file name

Run the recorded file

aplay test_record.wav

Next, open the SSH & Web Terminal in the Home Assistant and enter the command
pacmd list cards, where the available sound cards are displayed and it has a bluetooth headset

Output of sound cards with the command

ha audio info

The bluez_card.54_42_49_A5_56_AB profile cannot be assigned with the command

ha audio profile --card "1" --name "headset_head_unit"

image

It is not possible to assign a default input

ha audio default input --name 'bluez_card.54_42_49_A5_56_AB headset_head_unit'

image

I tried to add /etc/pulse/client.conf to the config

default-server = unix:/usr/share/hassio/audio/external/pulse.sock 

but in fact, it’s better not to do this, since the sound still works, and the microphone is not transmitted, but we lose the ability to control the device in Debian 11, the Dummy Output device is selected all the time. So I left the default-server as it is. The sound is transmitted to the speaker from both Debian 11 and Home Assistant

default-server =  

I tried using docker to assign by default

Viewing audio devices and assigning default devices

Withdraw all cards

docker exec -it hassio_audio pactl list

View the list of available maps

docker exec -it hassio_audio pactl list short sinks

Assign a default map

docker exec -it hassio_audio pactl set-default-sink 1

Did you look at this Select default audio device - #5 by arminJacobson , it look like HA need to assign the default input or it will not work, you probably need to change the profile of the sound device

" How to change the profile of a sound device

Thanks to this page from the Arch wiki, I was able to change the profile using pactl. The syntax is as follows:
pactl set-card-profile <symbolic-name> <profilename>

Thanks for the reply. I note that razer’s built-in sound and usb sound card work fine and transmit sound to the addon Rhasspy Assistant, if you add /etc/pulse/client.conf to the config, but this does not help for a bluetooth headset

default-server = unix:/usr/share/hassio/audio/external/pulse.sock 

I tried what you suggested and unfortunately it didn’t help, swears at input and output

I have tried various options


I tried the option with the choice of index or map

pactl set-card-profile

pactl set-card-profile 7 headset_head_unit

pactl set-card-profile

pactl set-card-profile 1 headset_head_unit

I looked at the specification of my old Sony DR-BT50 bluetooth headphones here. These headphones support A2DP, AVRCP, HFP, HSP profiles

And here’s what I found. Here write that

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.

I installed ofono using this instruction and it didn’t help. I note that ofono did not start successfully for me right away, since not everything went smoothly as in the instructions, but after I figured it out, I managed to launch ofono. Here’s how I made ofono run on Debian 11.6

Installing ofono on Debian 11.6

sudo apt update
sudo apt install ofono
sudo usermod -aG bluetooth pulse

Add to default.pa with the nano command /etc/pulse/default.pa

load-module module-bluetooth-discover headset=ofono

Added to ofono.conf with the nano /etc/dbus-1/system.d/ofono.conf command

  <policy user="pulse">
    <allow send_destination="org.ofono"/>
  </policy>

image

Adding /etc/apt/sources.list to the repositories

nano /etc/apt/sources.list
deb https://ppa.launchpadcontent.net/smoser/ppa/ubuntu focal main
deb-src https://ppa.launchpadcontent.net/smoser/ppa/ubuntu focal main

Launch and press Enter

sudo add-apt-repository ppa:smoser/ppa

Updating repositories

sudo apt update

If, after updating packages with the sudo apt update command , it swears

Repository “Index of /smoser/ppa/ubuntu lunar Release” does not contain a Release file.

Then you need to fix the OS version in the repository, specify focal instead of lunar. For understanding, Debian 11.6 has the name bullseye, and Ubuntu 20.04, which is built on the Debian build, has the name focal and impish. You need to edit all the files in the /etc/apt/sources.list.d folder/

ls /etc/apt/sources.list.d/

image

It was
image

Changing lunar to focal in the smoser-ubuntu-ppa-lunar.list file

cd /etc/apt/sources.list.d/
sed -i 's/\lunar\b/focal/g' smoser-ubuntu-ppa-lunar.list

After replacing lunar with focal, it should be like this

Install some pre-requisites:

sudo apt install devscripts build-essential software-properties-common -y

Add the signing key to your system:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B59D5F1597A504B7E2306DCA0620BBCF03683F77

Create the list file using the deb-src URL by adding the following to /etc/apt/sources.list.d/smoser-ubuntu-bluetooth-focal.list:

nano /etc/apt/sources.list.d/smoser-ubuntu-bluetooth-focal.list

deb-src http://ppa.launchpad.net/smoser/bluetooth/ubuntu focal main

Updating repositories

sudo apt update

After updating the packages with the sudo apt update command, it will swear again

Repository “Index of /smoser/ppa/ubuntu lunar Release” does not contain a Release file.

Repeat and change lunar to focal in the new smoser-ubuntu-bluetooth-focal.list file

cd /etc/apt/sources.list.d/
sed -i 's/\lunar\b/focal/g' smoser-ubuntu-bluetooth-focal.list

After that, you can ignore the warnings

Repository “Index of /smoser/ppa/ubuntu lunar Release” does not contain a Release file.

NOTE: If you want to try a different Ubuntu release instead of focal make sure you consult the mapping

At this point you should be able to run sudo apt update and not see any errors.

As noted above and in the referenced docs, we need to build a Debian package and can’t use what is in the PPA directly.

I try and stay organized:

mkdir -p ~/ppa/pkg-ofono-phonesim
cd ~/ppa/pkg-ofono-phonesim
apt install qtbase5-dev qtdeclarative5-dev -y
apt source -t focal --build ofono-phonesim

Если все сделано правильно, то будет вот так

At the end we should have the file ofono-phonesim_1.21-16-gadf231a8-0smoser0_amd64.deb
image

Now you should have a .deb file in the current directory so you can just install it:

sudo dpkg -i ofono-phonesim_1.21-16-gadf231a8-0smoser0_amd64.deb

Create a file called /etc/ofono/phonesim.conf with the following contents:

[phonesim]
Driver=phonesim
Address=127.0.0.1
Port=12345

image

Then we do as in the instructions, but with some changes

Create systemd Services to Manage ofono and ofono-phonesim

This is where we introduct what I think are a few improvements.

You will want to grab some official scripts from ofono:

sudo git clone git://git.kernel.org/pub/scm/network/ofono/ofono.git /opt/ofono

In addition, grab some scripts I wrote that make this all work better:

git clone https://github.com/davidnewman/control-phonesim.git ~/github.com/davidnewman/control-phonesim

Follow the instructions in the README.md file to set that up.

Create a file called /etc/systemd/system/ofono-phonesim.service with the following contents:

[Unit]
Description=Run ofono-phonesim in the background
Requires=ofono.service
After=ofono.service

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

[Install]
WantedBy=multi-user.target

Create a file called /etc/systemd/system/phonesim-enable-modem.service with the following contents:

[Unit]
Description=Enable and online phonesim modem
Requires=ofono-phonesim.service
    
[Service]
ExecStart=/opt/ofono/test/enable-modem /phonesim  /opt/ofono/test/enable-modem
ExecStart=/opt/ofono/test/online-modem /phonesim
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

After we have added it, we run the commands sequentially

sudo systemctl daemon-reload
sudo systemctl enable ofono-phonesim.service
sudo systemctl enable phonesim-enable-modem.service
sudo service phonesim-enable-modem start
sudo service phonesim-enable-modem status

If everything is done correctly, then when checking the status with the command, we should see that the phone sim-enable-modem service is running

sudo service phonesim-enable-modem status

You can also check whether ofono works in this way

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

Log out of the root account and run

systemctl --user restart pulseaudio

And at the end, we will comment out the repositories /etc/apt/sources.list. we won’t need them anymore

nano /etc/apt/sources.list
#deb https://ppa.launchpadcontent.net/smoser/ppa/ubuntu focal main
#deb-src https://ppa.launchpadcontent.net/smoser/ppa/ubuntu focal main

and delete the files moser-ubuntu-bluetooth-focal.list and smoser-ubuntu-ppa-lunar.list in /etc/apt/sources.list.d/

cd /etc/apt/sources.list.d/
rm smoser-ubuntu-bluetooth-focal.list  smoser-ubuntu-ppa-lunar.list

That’s it, now we go into debian 11, the microphone worked and works, the HSP profile is selected.

In the console, enter the command to display a list of sound cards and see that the headset_head_unit profile is activated

pacmd list-cards

Find out active profiles
pacmd list-cards | grep ‘active profile’

image

Then in /etc/pulse/client.conf I add to default-server =

nano /etc/pulse/client.conf
default-server = unix:/usr/share/hassio/audio/external/pulse.sock
autospawn = no

I save, log out of root and restart pulseaudio with the command

pulseaudio -k && pulseaudio --start

I go to the Home Assistant in the SSH & Web Terminal and enter

ha audio info 

there are no devices

next, I enter the pactl list cards and see my Sony DR-BT50 bluetooth headphones with the A2DP profile activated, and the headset_head_unit profile deactivated

pactl list cards

далее я пытаюсь активировать профиль headset_head_unit командами

pactl set-card-profile

pactl set-card-profile 7 headset_head_unit

pactl set-card-profile

pactl set-card-profile 1 headset_head_unit

pactl set-card-profile

pactl set-card-profile bluez_card.54_42_49_A5_56_AB headset_head_unit

I restart ha audio with the command, I see that the A2DP profile is activated

ha audio reload

Текст на русском (Text in Russian)

Спасибо за ответ. Отмечу, что встроенная звуковая и usb звуковая карта razer отлично работают и передают звук в аддон Rhasspy Assistant, если добавить в конфиг /etc/pulse/client.conf, но это не помогает для bluetooth гарнитуры

default-server = unix:/usr/share/hassio/audio/external/pulse.sock 

Попробовал, что вы предложили и к сожалению это не помогло, ругается на ввод и вывод

Я пробовал различные варианты


Попробовал вариант с выбором индекс или карты

pactl set-card-profile

pactl set-card-profile 7 headset_head_unit

pactl set-card-profile

pactl set-card-profile 1 headset_head_unit

Посмотрел спецификацию моих старых bluetooth наушников Sony DR-BT50 здесь. Эти наушники поддерживают профили A2DP, AVRCP, HFP, HSP

И вот что я нашел. Тут пишут, что

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.

Я установил ofono по этой инструкции и это не помогло. Отмечу, что ofono не сразу у меня успешно запустилось, так как не все шло гладко как в инструкции, но разобравшись, у меня получилось запустить ofono. Вот как я сделал, чтобы ofono запустилось на Debian 11.6

Установка ofono на Debian 11.6
sudo apt update
sudo apt install ofono
sudo usermod -aG bluetooth pulse

Добавим в default.pa командой nano /etc/pulse/default.pa

load-module module-bluetooth-discover headset=ofono

Добавил в ofono.conf командой nano /etc/dbus-1/system.d/ofono.conf

  <policy user="pulse">
    <allow send_destination="org.ofono"/>
  </policy>

image

Добавляем в репозитории /etc/apt/sources.list

nano /etc/apt/sources.list
deb https://ppa.launchpadcontent.net/smoser/ppa/ubuntu focal main
deb-src https://ppa.launchpadcontent.net/smoser/ppa/ubuntu focal main

Запускаем и нажимаем Enter

sudo add-apt-repository ppa:smoser/ppa

Обновляем репозитории

sudo apt update

Если после обновления пакетов командой sudo apt update будет ругаться

Repository “Index of /smoser/ppa/ubuntu lunar Release” does not contain a Release file.

То нужно исправить версию ОС в репозитории, вместо lunar указать focal. Для понимания, Debian 11.6 имеет имя bullseye, а Ubuntu 20.04 которая собрана на сборке Debian имеет имя focal и impish. Нужно отредактировать все файлы в папке /etc/apt/sources.list.d/

ls /etc/apt/sources.list.d/

image

Было
image

Меняем lunar на focal в файле smoser-ubuntu-ppa-lunar.list

cd /etc/apt/sources.list.d/
sed -i 's/\lunar\b/focal/g' smoser-ubuntu-ppa-lunar.list

После замены lunar на focal должно быть так

Install some pre-requisites:

sudo apt install devscripts build-essential software-properties-common -y

Add the signing key to your system:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B59D5F1597A504B7E2306DCA0620BBCF03683F77

Create the list file using the deb-src URL by adding the following to /etc/apt/sources.list.d/smoser-ubuntu-bluetooth-focal.list:

nano /etc/apt/sources.list.d/smoser-ubuntu-bluetooth-focal.list

deb-src http://ppa.launchpad.net/smoser/bluetooth/ubuntu focal main

Обновляем репозитории

sudo apt update

После обновления пакетов командой sudo apt update снова будет ругаться

Repository “Index of /smoser/ppa/ubuntu lunar Release” does not contain a Release file.

Повторяем и меняем lunar на focal в новом файле smoser-ubuntu-bluetooth-focal.list

cd /etc/apt/sources.list.d/
sed -i 's/\lunar\b/focal/g' smoser-ubuntu-bluetooth-focal.list

После этого можно игнорировать предупреждения

Repository “Index of /smoser/ppa/ubuntu lunar Release” does not contain a Release file.

NOTE: If you want to try a different Ubuntu release instead of focal make sure you consult the mapping

At this point you should be able to run sudo apt update and not see any errors.

As noted above and in the referenced docs, we need to build a Debian package and can’t use what is in the PPA directly.

I try and stay organized:

mkdir -p ~/ppa/pkg-ofono-phonesim
cd ~/ppa/pkg-ofono-phonesim
apt install qtbase5-dev qtdeclarative5-dev -y
apt source -t focal --build ofono-phonesim

Если все сделано правильно, то будет вот так

В конце у нас должен появиться файл ofono-phonesim_1.21-16-gadf231a8-0smoser0_amd64.deb
image

Now you should have a .deb file in the current directory so you can just install it:

sudo dpkg -i ofono-phonesim_1.21-16-gadf231a8-0smoser0_amd64.deb

Create a file called /etc/ofono/phonesim.conf with the following contents:

[phonesim]
Driver=phonesim
Address=127.0.0.1
Port=12345

image

Дальше делаем как в инструкции но с некоторыми изменениями

Create systemd Services to Manage ofono and ofono-phonesim

This is where we introduct what I think are a few improvements.

You will want to grab some official scripts from ofono:

sudo git clone git://git.kernel.org/pub/scm/network/ofono/ofono.git /opt/ofono

In addition, grab some scripts I wrote that make this all work better:

git clone https://github.com/davidnewman/control-phonesim.git ~/github.com/davidnewman/control-phonesim

Follow the instructions in the README.md file to set that up.

Create a file called /etc/systemd/system/ofono-phonesim.service with the following contents:

[Unit]
Description=Run ofono-phonesim in the background
Requires=ofono.service
After=ofono.service

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

[Install]
WantedBy=multi-user.target

Create a file called /etc/systemd/system/phonesim-enable-modem.service with the following contents:

[Unit]
Description=Enable and online phonesim modem
Requires=ofono-phonesim.service
    
[Service]
ExecStart=/opt/ofono/test/enable-modem /phonesim  /opt/ofono/test/enable-modem
ExecStart=/opt/ofono/test/online-modem /phonesim
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

После того как добавили запускаем команды последовательно

sudo systemctl daemon-reload
sudo systemctl enable ofono-phonesim.service
sudo systemctl enable phonesim-enable-modem.service
sudo service phonesim-enable-modem start
sudo service phonesim-enable-modem status

Если все сделано верно, то при проверки статуса командой мы должны увидеть, что служба phonesim-enable-modem запущена

sudo service phonesim-enable-modem status

\

Можно еще проверить работает ли ofono таким способом

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

Выходим из учетной записи root и запускаем

systemctl --user restart pulseaudio

И под конец в закомментируем репозитории /etc/apt/sources.list. они нам больше не понадобятся

nano /etc/apt/sources.list
#deb https://ppa.launchpadcontent.net/smoser/ppa/ubuntu focal main
#deb-src https://ppa.launchpadcontent.net/smoser/ppa/ubuntu focal main

и удалим файлы moser-ubuntu-bluetooth-focal.list и smoser-ubuntu-ppa-lunar.list в /etc/apt/sources.list.d/

cd /etc/apt/sources.list.d/
rm smoser-ubuntu-bluetooth-focal.list  smoser-ubuntu-ppa-lunar.list

На этом все, теперь заходим в debian 11, микрофон как работал, так и работает, профиль HSP выбран.

В консоле вводим команду вывести список звуковых карт и видим, что профиль headset_head_unit активирован

pacmd list-cards

Узнать активные профили
pacmd list-cards | grep ‘active profile’

image

Дальше в /etc/pulse/client.conf добавляю к default-server =

nano /etc/pulse/client.conf
default-server = unix:/usr/share/hassio/audio/external/pulse.sock
autospawn = no

Сохраняю, выхожу из root и перезапускаю pulseaudio командой

pulseaudio -k && pulseaudio --start

Захожу в Home Assistant в терминал SSH & Web Terminal и ввожу

ha audio info 

никаких устройств нет

далее ввожу и вижу свои bluetooth наушники Sony DR-BT50 у которых активирован профиль A2DP, а профиль headset_head_unit деактивирован

pactl list cards

далее я пытаюсь активировать профиль headset_head_unit командами

pactl set-card-profile

pactl set-card-profile 7 headset_head_unit

pactl set-card-profile

pactl set-card-profile 1 headset_head_unit

pactl set-card-profile

pactl set-card-profile bluez_card.54_42_49_A5_56_AB headset_head_unit

Перезапускаю ha audio командой, вижу, то активирован профиль A2DP

ha audio reload

And so, many hours of attempts to make the bluetooth microphone work were unsuccessful. I even installed Debian 11 on a virtual machine, installed a portainer and deployed a Rhasspy container with such parameters. There are only built-in sound cards, but there is no usb bluetooth headset. As they say, for the bluetooth headset to work in Rhasspy Assistant, you need to install bluez-alsa on Debian, but I can’t install and run bluez-alsa, even if I just compile according to this instructions, there are no necessary packages for Debian 10 and 11, which also need to be built.

version: "3.8"
services:
  rhasspy:
    image: rhasspy/rhasspy
    container_name: rhasspy
    privileged: true
    network_mode: bridge
    restart: unless-stopped #always
    ports:
      - 12101:12101 #http
      - 12183:12183 #mqtt
    devices:
      - /dev/snd/*
    volumes:
      - /home/docker/rhasspy/profiles:/profiles
      - /etc/localtime:/etc/localtime:ro
      - /home/docker/rhasspy/.config/pulse/cookie:/home/rhasspy/.config/pulse/cookie
      - /run/user/1000/pulse:/run/user/1000/pulse
      - /home/docker/rhasspy/pulseaudio:/etc/pulse/client.conf.d
    command: --user-profiles /profiles --profile ru
    environment:
      - PULSE_SERVER=unix:/run/user/1000/pulse/native
      - PULSE_RUNTIME_PATH=/run/user/1000/pulse

As a result, I just took a radio microphone and a portable speaker with which it works perfectly.



image

It works through the Rhasspy Assistant addon
image

In order for the bluetooth speaker to work, you need to add in /etc/pulse/client.conf

default-server = unix:/usr/share/hassio/audio/external/pulse.sock
autospawn = no

and restart pulseaudio with the command

pulseaudio -k && pulseaudio --start