简体   繁体   English

在 Linux 上使用 bluealsa 从蓝牙耳机录制音频

[英]record audio from bluetooth headset using bluealsa on Linux

I am using onboard Bluetooth on Raspberry pi zero and connected a Bluetooth speaker which also has a mic.我在 Raspberry pi zero 上使用板载蓝牙并连接了一个也有麦克风的蓝牙扬声器。 I want to record audio from this BT speaker mic.我想用这个 BT 扬声器麦克风录制音频。

I understand bluealsa command line can be used for this purpose, and also for playback of a.wav audio file.我了解 bluealsa 命令行可用于此目的,也可用于播放 a.wav 音频文件。

I could not succeed with bluealsa sco profile to record audio.我无法成功使用 bluealsa sco 配置文件录制音频。 (OS: Dietpi) The device is able to connect to pi, and can play wav files, using: aplay -D bluealsa:DEV=XX:XX:XX:XX:XX:XX,PROFILE=a2dp sample.wav (操作系统:Dietpi)设备可以连接到pi,并且可以播放wav文件,使用: aplay -D bluealsa:DEV=XX:XX:XX:XX:XX:XX,PROFILE=a2dp sample.wav

However, with arecord, it says its recording, but doesn't record anything, also it doesn't throw any error.但是,使用 arecord,它会说它的记录,但不记录任何内容,也不会引发任何错误。

using: arecord -f cd -D bluealsa:DEV=XX:XX:XX:XX:XX:XX,PROFILE=sco test.wav使用: arecord -f cd -D bluealsa:DEV=XX:XX:XX:XX:XX:XX,PROFILE=sco test.wav

Output: Recording WAVE 'test.wav': Signed 16 bit Little Endian, Rate 44100 Hz, Stereo Output:录制 WAVE 'test.wav':有符号 16 位小尾数,速率 44100 Hz,立体声

test.wav shows only 44 bytes on the system: test.wav 在系统上仅显示 44 个字节:

-rw-r--r-- 1 root root 44 Jun 9 15:38 test.wav -rw-r--r-- 1 根根 44 Jun 9 15:38 test.wav

when I try to play the recorded file, its just noise.当我尝试播放录制的文件时,它只是噪音。

Could anyone help?有人可以帮忙吗? Is recording from BTspeakers even supported in bluealsa package itself? bluealsa package 本身是否支持从 BTspeakers 录制?

Like I said, after a lot of head scratching, found some key aspects are missing while bluealsa service is getting started.就像我说的,经过一番摸索后,发现在 bluealsa 服务启动时缺少一些关键方面。

  1. By default, the bluealsa service is starting with only with "a2dp-source" profile.默认情况下,bluealsa 服务仅以“a2dp-source”配置文件开头。 This is only for playback of audio.这仅用于播放音频。 But for recording audio, it needs "a2dp-sink", "hfp-ag", and "hsp-ag" profiles.但要录制音频,它需要“a2dp-sink”、“hfp-ag”和“hsp-ag”配置文件。

  2. Use below command if you are using any raspberry or ubuntu based distributions.如果您使用任何基于 raspberry 或 ubuntu 的发行版,请使用以下命令。 "systemctl cat bluealsa" This shows the unit file for "bluealsa" service. “systemctl cat bluealsa” 这显示了“bluealsa”服务的单元文件。 it should have the below line for ExecStart.它应该有下面的 ExecStart 行。 ExecStart=/usr/bin/bluealsa -p a2dp-sink -p a2dp-source -p hfp-ag -p hsp-ag ExecStart=/usr/bin/bluealsa -p a2dp-sink -p a2dp-source -p hfp-ag -p hsp-ag

3.Usually what I have observed is with out any -p options passed to it. 3.通常我观察到的是没有任何 -p 选项传递给它。 change the unit file and restart the service.更改单元文件并重新启动服务。 Note: whenever any systemctl unit files are changed, the below command must be executed to take changes into effect.注意:每当任何 systemctl 单元文件发生更改时,必须执行以下命令才能使更改生效。

1. "systemctl daemon-reload"
2. systemctl restart bluealsa

4.Another thing to note is: using profile "sco" in asounrc file. 4.另外需要注意的是:在asounrc文件中使用配置文件“sco”。

recording audio should work after these changes!进行这些更改后,录制音频应该可以工作了! This is what worked for me!这对我有用! after a long ordeal!经过漫长的磨难!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM