New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Record from bluetooth device #7
Comments
Unfortunately, it is not implemented yet. Recording (from the headset, aka accessing build in microphone) requires HSP/HFP profile support. Like I said in #6, currently I'm trying to make it work. However, it is not trivial with the current bluealsa architecture (my bad) - so I'm doing some refactoring. The only possible way of recording with the current setup, it is to connect Bluetooth device, which will act as a source in the A2DP profile, e.g. iPhone or Android-powered smartphone. Current master snapshot has one "glitch" - in the amixer there is a recording device for HSP, so one might think recoding is possible, unfortunately not yet. |
I've just pushed prototype implementation of the SCO audio transfer (for HSP), which should provide access to the headset microphone. Try something like this:
The crucial thing is the usage of the SCO profile (in the future I might change this profile name, though). There is one important thing to mention. The behaviour of using A2DP and SCO simultaneously is headset dependent. On my headset it is not possible to listen to audio transferred with A2DP while the SCO connection is opened (recording and/or playing). |
It does not give me an error, but also it does not seem to record anything and it seems arecord also does not start counting the recorder time. It gives me a beep in my headset to tell me that something becomes active (but I am not sure exactly when this occurs, I also heard this some times when playing around before you implemented sco) Output on the
And on the
The file size of On the other hand when I do Can I try or post anything else to help? |
In logs everything looks OK (except one thing, A2DP profile seems not to be connected, which is odd, however is happens with my setup from time to time - try issuing connect (from the bluetoothctl) and see if A2DP will connect). 44 bytes in the WAV file is a header, so there will be no sound :) So the question is, if your Bluetooth headset is compatible with bluez. I might try to make some adjustments, so you will be able to test it. However, if you are sure that the microphone works (e.g. it works with PulseAudio) you might try to insert few debug statements in the io.c in these places:
Simple EDIT: For more thorough investigation you might try using tcpdump like this. Before connecting headset, run tcpdump as follows:
then connect device, and try to record audio - wait for few (3-5) seconds. Then see what is in logs using wireshark. There should be A LOT of packets from headset, which will indicate incoming audio, so the the problem is somewhere between kernel and HCI (or something). You might also try to use hcitop (shipped with bluez-alsa in the utils directory), just run it, and you should see incoming bandwidth (reported by the HCI). |
With PulseAudio I didn't even manage to play music to my headset. I have the feeling it uses a call protocol and I should answer the call from my headset, but that also did not work. I'm having the idea that when I want to record through The headset has three options to answer calls:
Number 1. and 2. both lead to the signal I'm just not sure if you can do it or if Edit:
quite stable, just the received and transmitted bytes per second sometimes go up/down a bit (but not connected to when I speak; but connected to when I push a button). E.g. when I push the answer button, it shortly goes up to 30 Bytes/s and then drops again. Every few seconds it goes to 6 Bytes/s. So does not really look as if any audio is transmitted. If I on the other hand play some music to my headset with
I assume if there was some transfer of audio when recording, the RX should also be in the area of 20kB/s. |
I tried adding debug outputs, but everytime I add some debug code to your code, I get this error message on execution later:
I'm using the arch linux AUR package as base. At first, I tried adjusting it inline with sed - worked fine according to the code, but error above. Then I went as far as downloading the code from git and storing it to a zip file and adjusting the source path in Before each execution of the newly installed package I stopped and restarted md5sum for the main code is set to Confusion completed... |
Wow, pretty bit of a struggle you've got there :) But seriously now.
The 3 beeps sound (I guess) indicates that the audio gateway (e.g. phone) has initialized SCO link - the audio is about to be transferred. Incoming call might be indicated by the special RING message sent to the headset (I'm not supporting it right now), or playing "ring" tone. Please, try using aplay with the SCO profile as follows:
but make sure, that the test.wav is a 8000 Hz mono (this should eliminate necessary audio conversion, because the SCO link supports only monophonic sound with 8000 Hz sampling rate). If there is no sound in the earpiece, it is definitely something wrong. Also check
The debug line showing "+CKPD=200" is a good thing. It is a signal (with a compliance to HSP) transferred from the headset to the audio gateway (in this case bluealsa), which indicates "button pressed". The HSP standard has only this one message (it is not possible to distinguish buttons or any other user actions) available to notify that one wants to answer the call. After this message, audio gateway should start transferring audio, however bluealsa is playing (in the HSP mode) without waiting - which is OK according to the HSP standard. Buuuut, I'm not sure if it is mandatory to transfer the sound from the headset to the audio gateway (in this case, a sound picked up by the microphone) just after the SCO has been established. So, the cause of this "issue" might lay somewhere here.
The transfer rate for SCO should be about 15000 bytes/s in both directions - RX/s TX/s. Though, the TX/s should only be "activated" when one is using playback device (aplay ... PROFILE=sco ...). For A2DP with SBC encoding, it is about 30000 bytes/s. And just one question, are you able to use this earpiece with a smarphone (preferable Android-based) or any other device or OS? And for testing, it might be better to compile bluealsa from the source code all the way up. Just compile it (without |
Hi, I don't know if you are still using bluez-alsa, but if yes, you might try to use a fresh master snapshot. Recently there was "exterminated" one bug (#22) which might have been related to this issue. |
Hello, I've tried the above: |
I also need to know how to get arecord working with a bluetooth device. With the following in .asoundrc, aplay works and arecord starts, but ignores duration and never stops.
|
@NA-Dev I am facing the same problem. Did you get it resolved? |
Please, use oFono backend for HFP profile - #172. Internal HFP support is not "production ready". |
I have a device that has both mic and speaker. bluetoothctl says that the device can act as both audio source and audio sink (but it does not show headset or handsfree). I have started bluealsa with both -p a2dp-source and -p a2dp-sink. Nevertheless, I am not able to get the audio stream from the mic (the device audio source profile). |
@saiedt please, post the output of bluetoothctl which shows profile listing (preferably in new github issue).
Yes, you are right, accessing backchannel is not yet supported in bluez-alsa master branch. |
After a lot of head scratching, I think I found what was going wrong. I saw some key aspects are missing when bluealsa service is getting started. By default, the bluealsa service is starting with only with "a2dp-source" profile. This is only for playback of audio. But for recording audio, it needs "a2dp-sink", "hfp-ag", and "hsp-ag" profiles. Use below command if you are using any raspberry or ubuntu based distributions. "systemctl cat bluealsa" This shows the unit file for "bluealsa" service. it should have the below line for ExecStart. 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. 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.
recording audio should work after these changes! This is what worked for me! after a long ordeal! |
Do you know if it's possible to use
arecord
together withbluealsa
? I managed to fix the problem from #6 by disablingpulseaudio-bluetooth
and can now play music through my bluetooth headset withaplay
, butarecord
still gives me the same error. Would I have to set different parameters for device input than for output?Again I try to provide a full log.
My /etc/asound.conf contains:
So let's start from a freshly booted system (# indicates root, ~ indicates user):
Output so far:
Going on:
New output:
Headset tells me "PC connected".
Going on:
no output, nice.
Gives the following output and plays the applause in my ear:
And then:
Gives the output:
On the
bluealsa
output we now have the new output (for both aplay and arecord, I forgot to split them...):The text was updated successfully, but these errors were encountered: