~roadmr/checkbox/912946

« back to all changes in this revision

Viewing changes to scripts/audio_detect_silence

Imported scripts and jobs from Platform Services.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
OUTPUT=`mktemp -u`.wav
 
4
GST_COMMAND="gst-launch audiotestsrc wave=sine freq=512 ! audioconvert ! audioresample ! gconfaudiosink"
 
5
#SOX_COMMAND="rec -q -r 44100 -p | sox -p $OUTPUT silence -l 1 00:00:00.5 -45d -1 00:00:00.5 -45d"
 
6
REC_COMMAND="rec -q -r 44100 $OUTPUT"
 
7
SOX_COMMAND="sox $OUTPUT $OUTPUT.1.wav silence -l 1 00:00:00.5 -45d -1 00:00:00.5 -45d"
 
8
 
 
9
# Start playing a sine wave
 
10
$GST_COMMAND &
 
11
GST_PID=$!
 
12
 
 
13
# Listen for it on the audio input
 
14
$REC_COMMAND &
 
15
REC_PID=$!
 
16
 
 
17
# Wait a bit, then stop playing
 
18
sleep 2
 
19
kill $REC_PID $GST_PID
 
20
 
 
21
# Look for silence
 
22
$SOX_COMMAND
 
23
 
 
24
# See if the filesize > 80 bytes on the output file
 
25
# (80 bytes is the largest wav file that will be generated for silence,
 
26
# so if we have that size we detected nothing but silence)
 
27
FILESIZE=`stat -c%s "$OUTPUT.1.wav"`
 
28
rm "$OUTPUT" "$OUTPUT.1.wav"
 
29
if [ "$FILESIZE" == "" ]
 
30
then
 
31
    echo "Unable to find output file." >&2
 
32
    exit 2
 
33
fi
 
34
 
 
35
if [ "$FILESIZE" -lt "81" ]
 
36
then
 
37
    echo "No audio detected." >&2
 
38
    exit 1
 
39
else
 
40
    echo "$FILESIZE bytes of audio recorded."
 
41
    exit 0
 
42
fi