I used to have a script which basically, returned the current temperature from a website. This was done with wget then awk to return the "Temperature" as a variable then I used sox to create a file saying the Temperature is etc.
The website has changed and I am having trouble re-writing it.
This is what I have:
URL='https://wttr.in/rhyl'
temp="wget -q -O- "$URL" | awk -F\' 'data-value/{print $1 }'| head -1)"
sox -V1 -c 1 silence.wav base.wav $temp.wav temp-dry.wav
sox -V1 -m temp-bed2.wav temp-dry.wav tempfx.wav
sox -V1 tempfx.wav tempfx+15db.wav vol 9 db
sox -V1 temp-dry.wav temp-dry+10db.wav vol 10 db
I'm happy with the sox bit so far, I just cant seem to return the variable i.e. "12" from the temperature section of wttr.in
The desired output of $temp is just number no special characters i.e $temp = 12
temp="wget..." is just storing the string "wget..." in the variable temp, it's not executing the command wget... if that's what you intended there then you should be doing temp="$(wget...)" instead. Try temp="$date"; echo "$temp" vs temp="$(date)"; echo "$temp" to see the difference.
This is a version bash file that updates and audio file for the current temperature, for the radio station jingle.
#/////Get weather for where you want thanks to User3439894 and Bengamin W. /////
temp="$(curl -s https://wttr.in/rhyl?format=%t | grep -Eo [0-9]+)"
# ////use sox to make the dry file outof pre-defind wav files/////
sox -V1 -c 1 silence.wav base.wav $temp.wav temp-dry.wav
# //// Here I use sox again to create a wav file with start and end jingle /////
sox -V1 -m temp-bed2.wav temp-dry.wav tempfx.wav
# //// Using sox again I boost the audio by what is required 15db and 10 db///
sox -V1 tempfx.wav tempfx+15db.wav vol 9 db
sox -V1 temp-dry.wav temp-dry+10db.wav vol 10 db
I then use crontab to run this bash script as a cronjob.
thanks everyone
Alex
Related
How do I change the sample rate for every file in the folder?
I have the following code and it just erases the files -- the file size becomes 0.
for i in wav/*.wav; do
sox -r 8000 -e unsigned -b 16 -c 1 "$i" "$i"
done
Why is that?
sox -r 8000 -e unsigned -b 16 -c 1 "$i" "$i"
Your not using $o (the output file) anywhere - looks like you're trying to input and output from the same file (just a guess - not familiar with sox)
One approach would be to write to a temporary output file and then move that over the top of the input file:
for fname in wav/*.wav; do
TMP_OUT=$(mktemp)
sox -r 8000 -e unsigned -b 16 -c 1 "$fname" $TMP_OUT
mv $TMP_OUT $fname
done
The danger here is that you lose the input file if something goes wrong. I would check the result of sox and only overwrite the input file if sox was successful.
ls -lrt *wav|wc -l --> 2160
Got around 2k audio files with sample rate 8k. Need to make an script to convert all the files to 16k Sample rate.For now Usig SOX for converting 1 file at a time.
For eg. :-
sox 9560850166.wav -r 16000 -b 16 -c 1 file1.wav
Need an script so that next audio files will be selected from the directory and SOX will be done to change sample rate and it will be saved with a new file name like file1.wav, file2.wav etc...
Run the below for loop from the directory containing wave files
a=0;
for i in `ls *.wav`;
do
let a++;
echo "Processing file $i"
sox $i -r 16000 -b 16 -c 1 file$a.wav
done
You do not need a script for this combination of find and exec will do the job
Use following command
find ./ -name "*wav" -exec sox {} -r 16000 -b 16 -c 1 {}.16000.wav \;
With this new audio file should get created with .16000.wav appended in original file name.
#!/bin/bash
i=0;
for filename in /home/mrityunjoy/myWork/audio_files/*.wav; do
i=$((i+1));
sox "$filename" -r 16000 -b 16 -c 1 "file$i.wav"
done
This will give the output in the directory we run the script.
I am trying to manage files created by my camera.
I got 2 folders one for RawFiles and another for Proxy files.
I want to loop through all the files in RawFiles folder, get the modified date and find the matching file with the same modified date.
I have the following script so far (you may need to change the file path)
I couldn't find a better way to "find" a file that matches an exact time stamp. I've commented out the line that's supposed to find the file matching the timestamp.
I'd like to keep this working on MacOS terminal without any dependency on perl etc.
#!/bin/bash
echo "Start Renaming Proxy files matching RAW files."
fmt='%Y%m%d%H%M%S'
RAWFILES=("/Volumes/RAWCard/"*.CRM)
PROXYDIR="/Volumes/ProxyCard/DCIM"
for f in "${RAWFILES[#]}"
do
echo "${f}";
export STAMP="$(stat -f "%Sm" -t "$fmt" "$f")"
echo "${STAMP}"
echo "1"
# find $PROXYDIR -type f -newermt "${STAMP}" ! -newermt "${STAMP}"
echo "Parse"
date -j -f %s -v +1S "${STAMP}" +"$fmt"
done```
Not certain I understand what you are up to, but this should help. You can use stat to get the modification (or access, change or birth time) in seconds since 1st January 1970 (epoch) of a whole bunch of files in one go like this:
stat -f "%m %SN" RAWCard/*
Sample Output
1511359473 RAWCard/step1.png
1511359474 RAWCard/step2.png
1512638778 RAWCard/step3.png
If you do that for both directories, you can then use join to join lines on the common field (the time):
stat -f "%m %SN" RAWCard/* > raw
stat -f "%m %SN" ProxyCard/* > proxy
join raw proxy
Sample Output
1511359473 RAWCard/step1.png ProxyCard/step1.png
1511359474 RAWCard/step2.png ProxyCard/step2.png
1512638778 RAWCard/step3.png ProxyCard/step3.png
Or, you can do it all in one go:
join <(stat -f "%m %SN" RAWCard/*) <(stat -f "%m %SN" ProxyCard/*)
If you want to then remove the timestamp field, you can do:
join -o 1.2,2.2 ...
You can also read the pairs in a loop:
join -o 1.2,2.2 ... | while read a b ; do
echo $a is friends with $b
done
May I suggest you always carefully check the resulting number of files is correct - since you will have problems if you have two images shot in the same second, or no matching image shot in the same second.
Working Script --
echo "Start Renaming Files"
RAWFILES="/Volumes/RAWCard/CRM/REEL_002/*"
PROXYDIR="/Volumes/ProxyCard/DCIM/136_1205/*.MP4"
stat -f "%m %SN" /Volumes/RAWCard/CRM/REEL_002/*.CRM > raw
stat -f "%m %SN" /Volumes/ProxyCard/DCIM/136_1205/*.MP4 > proxy
join raw proxy
join -o 1.2,2.2 raw proxy | while read a b; do
echo $a is friends with $b
rawfilebasename=$(basename "$a")
rawfilename="${rawfilebasename%.*}"
echo $rawfilename
proxydirname=$(dirname "$b")
proxyfilename=$(basename "$b")
proxyextension="${proxyfilename##*.}"
echo $proxydirname/$rawfilename.$proxyextension
mv $b $proxydirname/$rawfilename.$proxyextension
done
I have a script, wacaw (http://webcam-tools.sourceforge.net/) that outputs video from my webcam to a file. I am trying to basically stream that to some sort of display i.e vlc, quicktime, etc to get a "mirror" type effect.
Aside from altering the source code for wacaw, is there any way to force a script's file output to stdout so I can pipe it to something like vlc? Is it even possible to stream video like that?
Thanks for your help!
UPDATE: just to clarify:
running the wacaw script is formatted as follows:
./wacaw --video --duration 5 --VGA myFile
and it outputs a file myFile.avi. If I try to do a named pipe:
mkfifo pipe
./wacaw --video --duration 5 --VGA pipe
it outputs a file pipe.avi
You can use named pipes. You use mkfifo to create the pipe, hand that filename to the writing process and then read from that file with the other process. I have no idea if video in particular would work that way, but many other things do.
At least in bash you can do like this:
Original command:
write-to-file-command -f my-file -c
Updated command:
write-to-file-command -f >(pipe-to-command) -c
write-to-file-command will think >(pipe-to-command) is a write-only file and pipe-command will receive the file data on its stdin.
(If you just want the output to stdout you could do
write-to-file-command >(cat)
)
You may also try using tail -F myFile.avi:
# save stdout to file stdout.avi
man tail | less -p '-F option'
(rm -f myFile.avi stdout.avi; touch myFile.avi; exec tail -F myFile.avi > stdout.avi ) &
rm -f myFile.avi; wacaw --video --duration 1 --VGA myFile
md5 -q myFile.avi stdout.avi
stat -f "bytes: %z" myFile.avi stdout.avi
# pipe stdout to mplayer (didn't work for me though)
# Terminal window 1
# [mov,mp4,m4a,3gp,3g2,mj2 # ...]moov atom not found
#rm -f myFile.avi; touch myFile.avi; tail -F myFile.avi | mplayer -cache 8192 -
# Terminal window 2
#rm -f myFile.avi; wacaw --video --duration 1 --VGA myFile
The following works very nicely to determine the length of various audio/video files:
mplayer -identify file.ogg 2>/dev/null | grep ID_LENGTH
However, I want to kill mplayer's output so I can determine the length of many files more efficiently. How do I do that?
The MPlayer source ships with a sample script called midentify, which looks like this:
#!/bin/sh
#
# This is a wrapper around the -identify functionality.
# It is supposed to escape the output properly, so it can be easily
# used in shellscripts by 'eval'ing the output of this script.
#
# Written by Tobias Diedrich <ranma+mplayer#tdiedrich.de>
# Licensed under GNU GPL.
if [ -z "$1" ]; then
echo "Usage: midentify.sh <file> [<file> ...]"
exit 1
fi
mplayer -vo null -ao null -frames 0 -identify "$#" 2>/dev/null |
sed -ne '/^ID_/ {
s/[]()|&;<>`'"'"'\\!$" []/\\&/g;p
}'
The -frames 0 makes mplayer exit immediately, and the -vo null -ao null prevent it from trying to open any video or audio devices. These options are all documented in man mplayer.
FFMPEG can give you the same information in a different format (and doesn't attempt playing the file):
ffmpeg -i <myfile>
There's another FF-way in addition to #codelogic's method, which doesn't exit with an error:
ffprobe <file>
and look for the duration entry.
Or grep for it directly in the error stream:
ffprobe <file> 2> >(grep Duration)
looks like there are a few other libs available, see time length of an mp3 file
Download your .mp3 file, play it with your Player (ex. Windows Media Player) and the player will show the total time at the end of play.