Piping output from aplay to arecord in centos - linux

I am trying to automate some tests for a websocket client. This client connects to a server on command and the server is basically a speech to text engine. The client supports audio streaming from a microphone, such that people can record themselves in real time and transmitting it to the engine. I am running the client in a centos VM which does not have a physical sound card so I decided to simulate one using
modprobe snd-dummy
My plan is to pipe the output of
aplay audioFile.raw
to the input of
arecord test.raw -r 8000 -t raw
so that I can use that simulate the microphone feature. I read online that the file plugin for ALSA can pipe the results of one command to the next so I made the following modifications to the .asoundrc file in my root directory:
pcm.!default {
type hw
card 0
}
pcm.Ted {
type file
slave mySlave
file "| arecord test.raw -r 8000 -t raw"
}
pcm_slave.mySlave {
pcm "hw:0,0"
}
ctl.!default {
type hw
card 0
}
When I try the following command:
aplay audioFile.raw -D Ted
It seems to run fine but the output of test.raw seems to contain only silence... Does anyone know what I am doing wrong, I am very new to ALSA so if anyone can point me in the right direction, it would be greatly appreciated. Thanks!

Issue Fixed, instead of using snd-dummy I used snd-aloop and audio correctly pipes refer to this question:
Is it possible to arecord output from dummy card?

Related

Apply EQ to audio in and monitor audio out?

I am trying to make it possible to take the microphone input, have the input be filtered by the ALSA EQ plugin (or any other controllable EQ), and hear the live filtered output through headphones. I am using a RPI on Raspbain Buster. How might I accomplish this?
You can use the ALSA equal plugin to have a equaliser on by default.
First you have to install the plugin :
sudo apt-get install libasound2-plugin-equal
Then you should setup your asoundrc to set it to the default route, save the following to ~/.asoundrc :
#hooks [
{
func load
files [
"~/.asoundrc"
]
errors false
}
]
pcm.!default {
type plug
slave.pcm plugequal;
}
ctl.equal {
type equal
}
pcm.plugequal {
type equal
slave.pcm "plughw:ALSA,0"
}
pcm.equal {
type plug
slave.pcm plugequal
}
Finally you can alter the eq like so :
alsamixer -D equal
You can listen to the sound while you are adjusting the EQ by playing audio at the sample time :
aplay audioFile.wav
Now if you want to route your microphone to the output through the equaliser, then you probably want to pipe arecord to aplay like so :
arecord -Dplughw:mic -f cd | aplay
NOTE: Change "plughw:mic" above to the actual microphone you are using.
For example if I use my Audio Injector stereo or Ultra soundcard (which both have electret microphones on board) then I would setup their mixers to caputre using the onboard mirophones using alsamixer
alsamixer -Dhw:0
Then I would replace plughw:mic with plughw:0 as they are always the 0 card on my system.
arecord -Dplughw:0 -f cd | aplay

How do I get amixer PCM numid=3 to work on Raspberry Pi 4?

I have a Raspberry Pi 4 with speakers connected to the 3.5mm jack. I have no HDMI connected, but I have the standard 7 inch monitor connected. It runs raspbian.
Edit: I found out that this was normal behaviour due to an OS update, se my comment below.
If I run amixer cset numid=3 1 I get the error amixer: Cannot find the given element from control default.
If I run amixer contents there are no numid=3, I only get:
numid=2,iface=MIXER,name='Headphone Playback Switch'
; type=BOOLEAN,access=rw------,values=1
: values=on
numid=1,iface=MIXER,name='Headphone Playback Volume'
; type=INTEGER,access=rw---R--,values=1,min=-10239,max=400,step=0
: values=0
| dBscale-min=-102.39dB,step=0.01dB,mute=1
So PCM playback route with numid=3 is missing, and 1+2 say Headphone instead of PCM, that is the normal as far as I can tell from the interweb.
I can still play things with aplay and omxplayer (I'm not sure if it is mono or stereo).
But some other things fails, which I thought might be because of this. If I run espeak, and similar with pyttsx3 in python, I get screens full of errors, a few of the lines are:
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
Cannot connect to server socket err = No such file or directory
jack server is not running or cannot be started
And that is what I actually would want to get to work.
If that is caused by the first error I don't know. But when I search for rPi sound problems, the cset-numid=3 "solution" seems to appear everywhere, and I can't use that...
Edit: So that turns out not to be the reason, the espeak problem is still there even if I revert to the old way with options in boot.txt.
I needed three days to find out how to use it on Raspberry Pi. I created an Shell Command. When you want to use Audio via 3.5mm Jack just write. You can let the HDMI Cable connected.
sudo bash -c 'echo -e " defaults.pcm.card 1 \ndefaults.ctl.card 1" > /etc/asound.conf'
if you want to use the HDMI Audio output just change the number 1 to 0.
sudo bash -c 'echo -e " defaults.pcm.card 0 \ndefaults.ctl.card 0" > /etc/asound.conf'

Read raw USB data for port being used by VirtualBox

I have software for communicating with a serial device that only runs on Windows 7. My host machine is running Ubuntu 16.04, with Windows 7 in virtual box.
I've managed to set it up using USB device filters in VirtualBox settings so that Windows sees and can communicate with the device.
However I'd like to capture what's being sent to and from the device. I thought something as simple as cat /dev/ttyUSB0 would work but unfortunately when I start VirtualBox I get this in dmesg:
[31199.465270] vboxdrv: ffffffffc0df4020 VMMR0.r0
[31199.653494] vboxdrv: ffffffffc0ef7020 VBoxDDR0.r0
[31199.710573] VBoxNetFlt: attached to 'wlp1s0' / 98:54:1b:04:13:48
[31199.863579] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[31199.863674] ftdi_sio 1-3:1.0: device disconnected
So I don't know which file to monitor in /dev anymore. I suppose I might be able to try listen for the communication from Windows, but if I can I'd like to know if it's possible to monitor it from my host machine.
Edit:
This answer helped me for a start. I now get some cool looking stream on the terminal, next step is deciphering it, or if anyone has a better way I'm interested - it looks like the person who answered that question still has deciphering it as a TODO :-)
The fact that it was communicating with software in VirtualBox didn't really matter. This answer got me most of the way just by (as root):
modprobe usbmon
cat /sys/kernel/debug/usb/devices|less and search for device
cat /sys/kernel/debug/usb/usbmon/7u where 7 is the number from "Bus=" in the device table from step 2
From there is was just filtering the output.
A basic way could be just
cat /sys/kernel/debug/usb/usbmon/1u |cut -d\ -f9- | grep ^\n
But the device I was working with was constantly sending lines with just 4 characters, to filter out those I got the address word from the output line, and grepped for that. In my case I only wanted to capture "C" or callback output. I was also filtering for lines that contained more than just the default "0160" that the device was constantly outputting. To try understand the hex output I put a xxd -r -p at the end which gave me:
cat /sys/kernel/debug/usb/usbmon/1u | grep -e 'C Bi:1:005:1\s0\s\w*\s=\s0160\w' | cut -d\ -f8- | xxd -r
Where the grep is
grep -e 'C <address> <someotherstuff> = <always-output-string><anycharacter>
This still gave me this indecipherable junk below, but I don't know the format so I'm stuck here. Maybe the steps to read and filter will be useful for someone
>
O�UDQN��RG_JAMS142E DEFAULT0XXXXXXX�lSTz:�RSDU�vy��������������������������z�fff=�����{6zC"z�u6zC�z�H
;�����C��Af[���RSC�b ISD�EGIN
�CG_IEW0321:0407JUN12S��Z-�$''$'''C'''

ffmpeg get all sound devices(input/output)

I have downloaded the static build of ffmpeg for Windows and am trying to get all my sound devices (input/output) I have googled and found this command to retrieve audio devices , but when I use it ffmpeg arecord -l, it shows this error
Unrecognized option 'l'.
Error splitting the argument list: Option not found
what am missing here?
arecord is the command-line sound recorder and player for the ALSA soundcard driver which is available on Linux.
On Windows you can list the dshow devices with:
ffmpeg -list_devices true -f dshow -i dummy
See the Windows section of https://trac.ffmpeg.org/wiki/Capture/Desktop

Confusion in aplay Command.

Here i want to understand this commmand.
aplay -D hw:0,0 /opt/WL1271_demo_01/gallery/Pop.wav
Why we used asound.conf file.
we have to need update bluetooth address of hands free device in this file to play audio in handsfree device?
Can anybody Explain me aplay command and how its works?
why we used here -D hw:0,0 in this?
why we not used here -Dplug:bluetooth hw:0,0 ?
==================================================================
Here is my /etc/asound.conf file
pcm.!bluetooth {
type bluetooth
device 00:23:78:41:AB:9F
playback_ports {
0 alsa_pcm:playback_1
1 alsa_pcm:playback_2
}
capture_ports {
0 alsa_pcm:capture_1
1 alsa_pcm:capture_2
}
}
pcm.!default {
type plug
slave.pcm bluetooth
}
pcm.jack {
type jack
playback_ports {
0 alsa_pcm:playback_1
1 alsa_pcm:playback_2
}
capture_ports {
0 alsa_pcm:capture_1
1 alsa_pcm:capture_2
}
}
You are pointing aplay directly to some piece of hardware (hw:0,1 – second output of the first sound device) instead of letting it use your asound.conf definition. Try this instead:
aplay -D bluetooth -c 2 -f S16_LE abc.wav
Please note, that if you are using the ALSA interface this way anything else using that device (e.g. the Pulse Audio daemon) make this not work. You could probably use Pulse Audio instead of 'raw' ALSA, but I cannot help with that.
Update:
why we used here -D hw:0,0 in this?
How can we know? You provided the command. This means: use directly (this means: ignoring the aliases in asound.conf file) the first output of the first audio hardware (this usually means the output of your primary sound card).
why we not used here -Dplug:bluetooth hw:0,0 ?
Because the '-D' option accepts a single parameter. This can be 'hw:0,0', this can be 'plug:bluetooth', this can be any alias defined in the asound.conf file (like 'jack' or 'bluetooth' defined in your file), but it must be one parameter. 'plug:bluetooth hw:0,0' would be two parameters.
Why we used asound.conf file.
Not to have to provide a specific device address directly to each command. You may set the default in asound.conf and omit the '-D something' option all toghether
To provide more sophisticated configuration for the audio output
http://www.alsa-project.org/main/index.php/Asoundrc#The_naming_of_PCM_devices
Looks like you have a problem with your pulse audio setup. Here is a manual for ubuntu to troubleshoot bluetooth setups including aplay. Here is the manual for bluetooth setup for ubuntu.
From your configuration I see that you are missing the device name, namely "aplay -D default hw:0,1 -c 2 -f S16_LE abc.wav &". For my headset I have used an example here, and it works for me so far.

Resources