Current Level of Microphone Input - linux

How can I get the current audio input level of a microphone via a shell command under Ubuntu 12.04 LTS?
I checked out amixer to set the volume but could not find a way to get the audio input level at the time of the shell call.
Thank you in advance!

To get the level of the input signal, you have to actually record from the input device.
Use the -d 1 parameter for arecord to get a short file.
To read the level of the data in that file, use something like sox recordedfile.wav -n stat.

Based on the above answer, to get the maximum amplitude:
arecord -qd 1 volt && sox volt -n stat &> volt.d && sed '4q;d' volt.d

Related

How to record microphone to mp3 in Termux on Android?

I'm interested to try out Termux command line on Android to record microphone audio to mp3. I've tried running different commands but without much effect. Can anyone pinpoint correct example command to start recording of the microphone, to mp3, at a default location, for example downloads folder? (This is on Android Oreo)
termux-microphone-record
-d Start recording w/ defaults
-f Start recording to specific file
-l Start recording w/ specified limit (in seconds, unlimited for 0)
-e Start recording w/ specified encoder (aac, amr_wb, amr_nb)
-b Start recording w/ specified bitrate (in kbps)
-r Start recording w/ specified sampling rate (in Hz)
-c Start recording w/ specified channel count (1, 2, ...)
-i Get info about current recording
-q Quits recording
from https://wiki.termux.com/wiki/Termux-microphone-record
Termux does not (yet) appear to support recording directly to mp3 format. To get an mp3, you'll need to convert your recording using ffmpeg.
AWR Wide format has good quality for speech recording.
# Begin recording
termux-microphone-record -e awr_wide -f filename.amr
# Stop recording
termux-microphone-record -q
# Convert to mp3
ffmpeg -i filename.amr filename.mp3
The Below command will record for 10 sec and save your file.mp3 in your termux Home directory.
termux-microphone-record -d -f filename.mp3 -l 10
You need to install 1. the app for Android Termux.Api (i did from F-droid) and 2. the linux package (pkg install) 3. i had to give permission to microphone for termux.Api
after it records and stops automatically with -l.

Piping output from aplay to arecord in centos

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?

Set up basic Batch or Node.JS prompts for FFMPEG?

I have some game clips from Nvidia shadow play that I like to casually shorten and / or turn them into webms or keep them as mp4s. I use the same ffmpeg line for them. I do slightly change the line because of the input file, start time, and output file.
How could I set up something like a batch file (I was thinking maybe node as well) where it just asks for the input file, start time, and output file?
The current ffmpeg command line I use is like this:
ffmpeg -i desktop.mp4 -ss 00:01:50 -b 900000 -vf scale=640:trunc(ow/a/2)*2 output.webm
You can prompt for user input using the following pattern:
SET /P FILENAME=Enter Filename:
ECHO USER ENTERED %FILENAME%
So with your code you'd setup your 3 variables then use:
ffmpeg -i "%INFILE%" -ss %STARTTIME% -b 900000 -vf scale=640:trunc(ow/a/2)*2 "%OUTFILE%"

Capture nethogs output in log file

I want to check the network bandwidth used by my process.
For this i found that nethogs tool is useful. Using this tool i can see which process is eating up a network bandwidth and process behaviour.
But how do I capture data from nethogs for a my process and store it into log file ?
You can run nethogs in background in tracemode and write output to a file like this:
sudo nethogs -t eth1 &> /var/tmp/nethogs.log &
Download and build the nethogs-parser as described here.
Then after you have accumulated enough data you can run the parser to see the results:
./hogs -type=pretty /var/tmp/nethogs.log
Make sure to kill the running nethogs process when you are done collecting data.
More info here on automating the task.
I dont know when these options got implemented but you can use nethogs -t or nethogs -b, the pid and user are strangely placed at the end of the pid command string, but easy enough to parse.
I think you need to use the latest cvs version 0.8.1-SNAPSHOT
You can use this command to capture output:
nethogs -d 5 | sed 's/[^[:print:][:cntrl:]]//g' > output.txt
The right command of nethogs is
nethogs -d 1 eth0 > output.txt
You need to specify the network interface otherwise, the default interface eth0 will be used. Sometime, nethogs might not show the proper output because of the network interface. It is always better to provide the network interface and generate some traffic during the experimentation. You can print the output to a file by adding > output.txt
-d argument specifies how frequently the output will be shown. Here, I gave 1, this indicates that the output will be shown per second.
Hope this might be useful.

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