hide output of aplay shell command - linux

Is there a way to hide the output of the aplay command when play a sound?
I tried this without success
$ aplay ~/.zsh/sounds/done.wav >> /dev/null
Playing WAVE '/home/oscar/.zsh/sounds/done.wav' : Unsigned 8 bit, Rate 11025 Hz, Mono
I'll appreciate your help.

Simply add the -q option:
aplay -q ~/.zsh/sounds/done.wav
No need to redirect stdout to /dev/null there.
Another note: aplay actuall sends messages to /dev/stderr (fd 2). You can also nullify the output by sending it to /dev/null:
aplay ~/.zsh/sounds/done.wav 2>/dev/null
You can see more options with aplay --help. This line is about -q:
-q, --quiet quiet mode

Related

Understanding a script which uses ffmpeg to send rtmp input to node.js script

I was trying to understand this shell script which uses ffmpeg to take an rtmp input stream and send it to a node.js script. But I am having trouble understanding the syntax. What is going on here?
The script:
while :
do
echo "Loop start"
feed_time=$(ffprobe -v error -show_entries format=start_time -of default=noprint_wrappers=1:nokey=1 $RTMP_INPUT)
printf "feed_time value: ${feed_time}"
if [ ! -z "${feed_time}" ]
then
ffmpeg -i $RTMP_INPUT -tune zerolatency -muxdelay 0 -af "afftdn=nf=-20, highpass=f=200, lowpass=f=3000" -vn -sn -dn -f wav -ar 16000 -ac 1 - 2>/dev/null | node src/transcribe.js $feed_time
else
echo "FFprobe returned null as a feed time."
fi
echo "Loop finish"
sleep 3
done
What is feed_time here? What does it represent?
What is this portion doing - 2>/dev/null | node src/transcribe.js $feed_time?
What is the use of sleep 3? Does this mean that we are sending audio stream to node.js in chuncks of 3 seconds?
feed_time variable represents standard output of ffprobe command. This value needs to be passed to node script.
- character doesn't have special meaning in bash, i.e. it is interpreted by ffmpeg command itself (see here). According to ffmpeg docs:
A - character before the stream identifier creates a "negative"
mapping. It disables matching streams from already created mappings.
2>/dev/null is a redirection that sends standard error output of ffmpeg command to /dev/null device, thus effectively discarding the error output (see here). It is done because you want only the standard output (not error output) to be passed to node script.
| is a pipe. It sends standard output of ffmpeg command to standard input of node script.
sleep just delays execution of a script.

Sox Is Throwing A Random Error: Option A Isn't Recognized

I am running this command:
sox -t mp3 $(ls -1 /home/pi/Desktop/Music/*.mp3|sort -R) -t wav -r 44100 - | sudo ./pi_fm_rds -freq 104.5 -audio - -ps ZSFM -rt ZSFM
This is the result:
sox WARN getopt: option `A' not recognized
sox FAIL sox: invalid option
When I was running this command sox worked fine:
sox -t mp3 /home/pi/Desktop/Music/*.mp3 -t wav -r 44100 - | sudo ./pi_fm_rds -freq 104.5 -audio - -ps ZSFM -rt ZSFM
The new command is to have sox shuffle through the files in a directory randomly, but its giving me this wierd error. How can I make it work? I've done tons of research, but I can't find anything about 'option A' anywhere.
The problem was the whitespace in file names - all I had to do was change, for example, 'dasa berta.mp3' to 'dasaberta.mp3'. One of the file names had 'A' in it, and the terminal took it as a separate command. It wasn't a sox problem, it was a me-using-terminal-problem.

Play an MP3 file as it's being written

I'm saving an fm station to an mp3 file using rtl_fm and sox.
rtl_fm to capture the signal and sox to transcode it to mp3.
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 | sox -traw -r8k -es -b16 -c1 -V1 - -tmp3 - | sox -tmp3 - some_file.mp3
Then I'm trying to play that file in a second terminal, as the mp3 is being written using:
play -t mp3 some_file.mp3
The problem is that it only plays up until the time the mp3 had at the time the play command was invoked.
How do I get it to play the appended mp3 over time, while it's being written?
EDIT:
Running on Raspberry Pi 3 (Raspian Jessie), NooElec R820T SDR
There are a couple of things here. I don't think sox supports "tailing" a file, but I know mplayer does. However, in order to have better control over the pipeline, using gstreamer might be the way to go, as it has a parallel event stream built into its effects pipeline.
If you want to stick with sox, I would first get rid of the redundant second invocation of sox, e.g.:
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 |
sox -ts16 -r8k -c1 -V1 - some_file.mp3
And in order to play the stream while transcoding it, you could multiplex it with tee, e.g.:
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 |
tee >(sox -ts16 -r8k -c1 -V1 - some_file.mp3) |
play -ts16 -r8k -c1 -
Or if you want them to be separate processes:
# Save stream to a file
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 > some_file.s16
# Encode stream
sox -ts16 -r8k -c1 -V1 some_file.s16 some_file.mp3
# Start playing the file at 10 seconds in
tail -c+$((8000 * 10)) -f some_file.s16 |
play -ts16 -r8k -c1 -

Check if a video file has subtitles

Is it possible to check if a video file has a subtitle using bash and get a simple answer like "yes" or "no". I don't need to know any details about the subtitles.
Maybe using ffmpeg?
This should display a 0 if subtitles are found, and 1 if not found.
ffmpeg -i video -c copy -map 0:s:0 -frames:s 1 -f null - -v 0 -hide_banner; echo $?
Bash
ffmpeg -i $filename 2>&1 | grep "Subtitle:"
Powershell
ffmpeg -i $filename 2>&1 | select-string "Subtitle:"
Explanation:
The ffmpeg command fails if no output file is provided, but the error message contains all information about the input file. The expression 2>&1 redirects error stream to standard output so it can be piped into grep/select-string command.

Streaming a file off a server

I am trying to stream the recorded audio from my raspberry pis to my desktop computer which handles pocketsphinx phenomenally. I can pipe the audio using
arecord -D plughw:1,0 -r 16000 -f S16_LE | ssh -C user#192.168.86.101 sox - test.wav
And then run it using
pocketsphinx_continuous -dict ~/4568.dic -lm ~/4568.lm -infile ~/test.wav
But once it reaches the end of the file, it stops, even though the file is still writing. Is there a way to keep it open?
Use named pipe instead of a regular file. Also you can file an issue at github.com/cmusphinx/pocketsphinx requesting that pocketsphinx_continious should be able to read from stdin. And of course you're welcome to submit such a patch.
To anyone else finding this,
arecord -D plughw:1,0 -r 16000 -f S16_LE | ssh -C user#192.168.86.101 pocketsphinx_continuous -infile /dev/stdin
is how to do it

Resources